/***
 * 富文本的功能性代码，对应工具栏上的功能实现
 * @Author: kevin.huang 
 * ****/

Kedit.prototype.flow = function () {
    this.flowOpen();
};
Kedit.prototype.flowOpen = function (dataJson, flowImg) {
    var width = this.$fixInput.width();
    var height = _getBody().height() - this.$fixInput.offset().top;
    var jqHref = $("script#flowjqplus").attr("src").replace("flowjqplus.js", "");
    var date = new Date();
    var diff = date.getMinutes() + "" + date.getSeconds() + date.getMilliseconds() + parseInt(Math.random() * 100);
    var src0 = jqHref.replace("flow/", "") + "jquery.min.js";
    var src1 = jqHref + "snap.svg-min.js";
    var src2 = jqHref + "config.js?t=" + diff;
    var src3 = jqHref + "flow-all-0.0.1.js?t=" + diff;
    var struct = '<div id="f_loading" style="padding:0;marign:0;padding-left:20px;"><i style="padding: 0;margin: 0;font-size: 14px;line-height: 1.5em;font-family: "Microsoft Yahei", Helvetica, Arial, sans-serif;color: #666666;" class="fa animate-spin fa-spin6"></i>loading........</div><div id="f_main" style="width:100%;height:100%;position: relative;display:none;"><div class="k_box_size" id="left_container"></div><div class="k_box_size" id="right_container"><div class="k_box_size" id="canvas_container" style="overflow:auto;"><svg tabindex="0" id="myflow" class="k_box_size" style="width:100%;height:100%;vertical-align:top;"></svg></div></div><div style="border-top:1px solid #40ADFF;border-right:1px solid #40ADFF;" class="k_box_size" id="top_container"><div id="f_title" style="float:left;font-size:16px;line-height:34px;height:100%;padding:0 18.5px;background: #40ADFF;color:#fff;">Bui-flow</div><div id="f_tools" style="margin-left:30px;float:left;line-height:34px;height:100%;padding:0 28px;"></div><div id="f_tools_r" style="float:right;line-height:34px;height:100%;padding:0 28px;"></div></div></div>';
    var onloadScript = '<script> var ivt = setInterval(function () { ' + "\n\r" + 'if (window.$ && window.$B && window.$B.Flow && window.$B.flowConfig && window.Snap)' + "\n\r" + ' {' + "\n\r" + ' clearInterval(ivt); $("body").css("position","relative");var $l = $("#f_loading").hide();$l.next().show(); parent._KBCreateFlow($B, $("#myflow")[0]); }' + "\n\r" + 'else{' + "\n\r" + 'console.log("等待资源加载完成.....");}},200);<\/script>';
    this.flowScriptSrcs = {
        src: [src0, src1, src2, src3],
        struct: struct,
        onloadScript: onloadScript,
        flowcss: jqHref + "flow.css"
    };
    var _this = this;
    window._KBCreateFlow = function ($_B, $el) {
        _this.flowIns = new $_B.Flow($el, {
            uploadIconUrl: _this.opts.uploadFlowIconUrl,
            onSave: function (json) {
                _this.flowIns.getImgBase64(function (base64, width, height) {
                    var fjson = _this.flowIns.toJson();
                    _this.flowIns.destroy(_this);
                    _this.insertFlow(base64, width, height, fjson);
                    _this.closeWindow();
                });
            }
        });
        if (dataJson) {
            _this.flowIns.drawByJson(dataJson);
        }
    };
    var bHeight = _getBody().height();
    if (height > bHeight) {
        height = bHeight;
    }
    this.openWindow({
        title: eConfig.label.drawFlow,
        width: width,
        height: height,
        contentFn: function (body, prs) {
        }
    }, {}, undefined, "flowDesignWindow");
    this.flowScriptSrcs = undefined;
    this.flowDesignWindow.data("rmDom", true);//窗口关闭即删除dom
    this.flowUpdateImg = flowImg;
};
/**插入流程图***/
Kedit.prototype.insertFlow = function (imgData, width, height, flowJson) {
    var id, _this = this;
    if (flowJson.id) {//执行更新
        id = flowJson.id;
        this.flowUpdateImg[0].src = imgData;
        this.flowUpdateImg.css({ width: width, height: height });
        if (typeof this.opts.onInsertFlowAfter === "function") {
            var updateImg = _this.flowUpdateImg;
            setTimeout(function () {
                _this.opts.onInsertFlowAfter(updateImg, flowJson, true);
            }, 50);
        }
    } else {
        var src = imgData;
        if (typeof this.opts.onInsertFlow === "function") {
            var tmp = this.opts.onInsertFlow(imgData);
            if (tmp) {
                src = tmp;
            }
        }
        var prs = {
            "undo": false,
            "needRange": false,
            "url": src,
            "width": width,
            "height": height,
            "position": "left"
        };
        var img = this.picture(prs);
        id = img.addClass("k_editor_flow_img").attr("id");
        if (typeof this.opts.onInsertFlowAfter === "function") {
            setTimeout(function () {
                _this.opts.onInsertFlowAfter(img, flowJson, false);
            }, 50);
        }
    }
    flowJson.id = id;
    this.FLOW_CACHE[id] = flowJson;
};
/**
 * 设置流程数据 内部调用setFlowCacheById
 * datas:流程数据数组
 * ***/
Kedit.prototype.setFlowDatas = function (datas) {
    for (var i = 0, len = datas.length; i < len; ++i) {
        this.setFlowCacheById(datas[i].id, datas[i]);
    }
};
/**id:流程id ，flowjson：流程json***/
Kedit.prototype.setFlowCacheById = function (id, flowJson) {
    this.FLOW_CACHE[id] = flowJson;
};
/**
* 打开边框设置窗口
* ***/
Kedit.prototype.openBorderForm = function (jqObj) {
    //console.log("打开 openBorderForm");
    var _this = this;
    _this.currentBorderObj = jqObj.addClass("k_editor_closed_section");
    this.onWindowClosed = function () {
        _this.currentBorderObj.removeClass("k_editor_closed_section");
        _this.currentBorderObj = undefined;
    };
    this.openWindow({
        title: eConfig.label.setborder,
        width: 350,
        height: 200,
        contentFn: function (body, prs) {
            if (!_this["borderForm"]) {
                _this["borderForm"] = $("<div style='width:100%;height:100%;position:relative;padding-left:40px;' class='k_box_size'></div>");
                _this["borderForm"].append(eConfig.borderForm);
                _this._createWindowColorPicker();
                var f = _this["borderForm"];
                var $_border_pos = f.find("#k_border_pos");
                var $_border_style = f.find("#k_border_style");
                var $_border_size = f.find("#k_border_size");
                var $_icon_color = f.find("#k_icon_color");
                var getBodyprexFn = function () {
                    var borderPosArray = [];
                    $_border_pos.children("._act").each(function () {
                        borderPosArray.push("border-" + $(this).attr("v") + "-");
                    });
                    return borderPosArray;
                };
                var posClickFn = function () {
                    var $o = $(this);
                    if ($o.hasClass("_act")) {
                        $o.css("background-color", 'transparent').removeClass("_act");
                    } else {
                        $o.css("background-color", '#2EF5FF').addClass("_act");
                    }
                    var exePrs, bsize, bcolor, bstyle;
                    var borders = getBodyprexFn();
                    if (borders.length === 0) {
                        exePrs = { "border": "none" };
                    } else {
                        bsize = $_border_size.val();
                        bcolor = $_icon_color.css("background-color");
                        bstyle = $_border_style.val();
                        var bcss = {};
                        for (var i = 0, len = borders.length; i < len; ++i) {
                            bcss[borders[i] + "style"] = bstyle;
                            bcss[borders[i] + "width"] = bsize;
                            bcss[borders[i] + "color"] = bcolor;
                        }
                        exePrs = bcss;
                    }
                    //执行边框修饰.....
                    //console.log("执行修饰>>>>>>>>" +  JSON.stringify(exePrs) );
                    _this.currentBorderObj.css("border", "none").css(exePrs);
                };

                //选择事件 ,行高，边框位置，边框类型
                var onSelectedFn = function () {
                    var $this = $(this);
                    var val = $this.val();
                    var exePrs = $.extend({}, prs);
                    var bstyle, bsize, bcolor, bcss, i, len, borders;
                    var elId = $this.attr("id");
                    if (elId === "k_border_style") {//边框类型
                        borders = getBodyprexFn();
                        if (borders.length === 0) {
                            exePrs = { "border": "none" };
                        } else {
                            bsize = $_border_size.val();
                            bcolor = $_icon_color.css("background-color");
                            bcss = {};
                            for (i = 0, len = borders.length; i < len; ++i) {
                                bcss[borders[i] + "style"] = val;
                                bcss[borders[i] + "width"] = bsize;
                                bcss[borders[i] + "color"] = bcolor;
                            }
                            exePrs = bcss;
                        }
                        //console.log("执行修饰>>>>>>>>" +  JSON.stringify(exePrs) );
                    } else if (elId === "k_border_size") {//边框大小
                        borders = getBodyprexFn();
                        if (borders.length === 0) {
                            exePrs = { "border": "none" };
                        } else {
                            bcolor = $_icon_color.css("background-color");
                            bstyle = $_border_style.val();
                            bcss = {};
                            for (i = 0, len = borders.length; i < len; ++i) {
                                bcss[borders[i] + "style"] = bstyle;
                                bcss[borders[i] + "width"] = val;
                                bcss[borders[i] + "color"] = bcolor;
                            }
                            exePrs = bcss;
                        }
                        //console.log("执行修饰>>>>>>>>" +  JSON.stringify(exePrs) );                       
                    }
                    _this.currentBorderObj.css("border", "none").css(exePrs);
                };

                $_border_style.on("change", onSelectedFn);
                $_border_size.on("change", onSelectedFn);
                //边框位置 
                $("<span class='_border_pos' v='left'  style='border:1px dashed #CCCCCC;border-left:2px solid #0000FF;cursor:pointer; display:inline-block;width:15px;height:15px;margin-right:8px;'></span>").appendTo($_border_pos).click(posClickFn);
                $("<span class='_border_pos' v='top'  style='border:1px dashed #CCCCCC;border-top:2px solid #0000FF;cursor:pointer; display:inline-block;width:15px;height:15px;margin-right:8px;'></span>").appendTo($_border_pos).click(posClickFn);
                $("<span class='_border_pos' v='right' style='border:1px dashed #CCCCCC;border-right:2px solid #0000FF;cursor:pointer; display:inline-block;width:15px;height:15px;margin-right:8px;'></span>").appendTo($_border_pos).click(posClickFn);
                $("<span class='_border_pos' v='bottom' style='border:1px dashed #CCCCCC;border-bottom:2px solid #0000FF;cursor:pointer; display:inline-block;width:15px;height:15px;margin-right:8px;'></span>").appendTo($_border_pos).click(posClickFn);

                var ifrPos = _this[_this.windowName + "_iframe"].offset();
                var picker = _this[_this.windowName].data("colorPicker");
                picker.opts.positionFix = {
                    left: ifrPos.left + 4,
                    top: ifrPos.top + 4
                };
                //边框颜色
                $_icon_color.mousedown(function () {
                    picker.hideImd(true);
                    picker.setTarget($(this));
                    var borders = getBodyprexFn();
                    var bstyle = $_border_style.val();
                    var bsize = $_border_size.val();
                    picker.opts.change = function (hex, opacity) {
                        if (borders.length > 0) {
                            var bcss = {};
                            for (var i = 0, len = borders.length; i < len; ++i) {
                                bcss[borders[i] + "style"] = bstyle;
                                bcss[borders[i] + "width"] = bsize;
                                bcss[borders[i] + "color"] = hex;
                            }
                            //var exePrs = { "border": bcss };
                            console.log("执行修饰>>>>>>>>" + JSON.stringify(bcss));
                            _this.currentBorderObj.css("border", "none").css(bcss);
                        }
                    };
                    picker.setValue($(this).css("background-color"), false);
                });

                f.find("button").click(function () {
                    _this.closeWindow();
                });

                _this["borderForm"].data("form", {
                    borderPos: $_border_pos,
                    borderStyle: $_border_style,
                    borderColor: $_icon_color,
                    borderSize: $_border_size
                });
            }
            //联动
            var borderCss;
            var border = _this._getJqObjBorders(_this.currentBorderObj);
            var form = _this["borderForm"].data("form");
            var colorPicker = _this[_this.windowName].data("colorPicker");
            form.borderPos.children().each(function () {
                var $o = $(this);
                if (border[$o.attr("v")]) {
                    $o.css("background-color", '#2EF5FF').addClass("_act");
                    borderCss = border[$o.attr("v")];
                } else {
                    $o.css("background-color", 'transparent').removeClass("_act");
                }
            });
            var fn1 = function (i, opt, prpName) {
                if (borderCss) {
                    if (borderCss[prpName] === opt.attr("value")) {
                        opt.prop("selected", true);
                    } else {
                        opt.prop("selected", false);
                    }
                } else {
                    if (i === 0) {
                        opt.prop("selected", true);
                    } else {
                        opt.prop("selected", false);
                    }
                }
            };
            form.borderStyle.children().each(function (i) {
                var opt = $(this);
                fn1(i, opt, "style");
            });
            form.borderSize.children().each(function (i) {
                var opt = $(this);
                fn1(i, opt, "width");
            });
            var trastColor;
            if (borderCss) {
                trastColor = colorPicker.getContrastColor(borderCss.color);
                form.borderColor.css({ "background-color": borderCss.color, "color": trastColor });
            } else {
                form.borderColor.css({ "background-color": "#666666", "color": "#ffffff" });
            }
            body.append(_this["borderForm"]);
        }
    }, {}, this.setWindowColorPickerPosition);
    this.setWindowColorPickerPosition();
},
/**
 * 设置colorpicker位置
 * ****/
Kedit.prototype.setWindowColorPickerPosition = function () {
    var _this = this;
    var winIfr = _this[_this.windowName + "_iframe"];
    if (winIfr) {
        var ifrPos = winIfr.offset();
        var win = _this[_this.windowName];
        if (win) {
            var picker = win.data("colorPicker");
            if (picker) {
                picker.opts.positionFix = {
                    left: ifrPos.left + 4,
                    top: ifrPos.top + 2
                };
            }
        }
    }
};
/***
 * 打开段落窗口
 * ***/
Kedit.prototype.openParagrapWindow = function (method, params, $btn) {
    var _this = this;
    if (!this.startPElement) {
        $B.alert(eConfig.label.selectedSectionTip, 3);
        return;
    }
    this.openWindow({
        title: eConfig.label.paragraph,
        width: 450,
        height: 300,
        contentFn: function (body, prs) {
            if (!_this["paragrapForm"]) {
                _this["paragrapForm"] = $("<div style='width:100%;height:100%;position:relative;' class='k_box_size'></div>");
                _this["paragrapForm"].append(eConfig.paragraphForm);
                _this._createWindowColorPicker();
                var f = _this["paragrapForm"];
                var userInputFn = function () {
                    var $t = $(this);
                    var id = $t.attr("id").replace(/_/g, "");
                    var v = $t.val();
                    if (/\d+/.test(v)) {
                        $t.removeClass("k_input_value_err");
                        var exePrs = $.extend({}, prs);
                        exePrs[id] = v;
                        _this.paragraph(exePrs);
                    } else {
                        $t.addClass("k_input_value_err");
                    }
                };
                var $_indent_ = f.find("#_indent_").on("input", userInputFn);
                var $_margin_top_ = f.find("#_margin-top_").on("input", userInputFn);
                var $_margin_bottom_ = f.find("#_margin-bottom_").on("input", userInputFn);
                var $_padding_left_ = f.find("#_padding-left_").on("input", userInputFn);
                var $_padding_right_ = f.find("#_padding-right_").on("input", userInputFn);
                var $_line_height_ = f.find("#_line-height_");
                var $_border_pos = f.find("#_border_pos");
                var $_border_style = f.find("#_border_style");
                var $_border_size = f.find("#_border_size");
                var $_icon_color = f.find("#_icon_color");

                var getBodyprexFn = function () {
                    var borderPosArray = [];
                    $_border_pos.children("._act").each(function () {
                        borderPosArray.push("border-" + $(this).attr("v") + "-");
                    });
                    return borderPosArray;
                };

                var posClickFn = function () {
                    var $o = $(this);
                    if ($o.hasClass("_act")) {
                        $o.css("background-color", 'transparent').removeClass("_act");
                    } else {
                        $o.css("background-color", '#2EF5FF').addClass("_act");
                    }
                    var exePrs, bsize, bcolor, bstyle;
                    var borders = getBodyprexFn();
                    if (borders.length === 0) {
                        exePrs = { "border": "none" };
                    } else {
                        bsize = $_border_size.val();
                        bcolor = $_icon_color.css("background-color");
                        bstyle = $_border_style.val();
                        var bcss = {};
                        for (var i = 0, len = borders.length; i < len; ++i) {
                            bcss[borders[i] + "style"] = bstyle;
                            bcss[borders[i] + "width"] = bsize;
                            bcss[borders[i] + "color"] = bcolor;
                        }
                        exePrs = { "border": bcss };
                    }
                    _this.paragraph(exePrs);
                };

                //选择事件 ,行高，边框位置，边框类型
                var onSelectedFn = function () {
                    var $this = $(this);
                    var val = $this.val();
                    var exePrs = $.extend({}, prs);
                    var bstyle, bsize, bcolor, bcss, i, len, borders;
                    //console.log("onSelectedFn " + val);
                    var elId = $this.attr("id");
                    if (elId === "_line-height_") {
                        exePrs["line-height"] = val;
                        _this.paragraph(exePrs);
                    } else if (elId === "_border_style") {//边框类型
                        borders = getBodyprexFn();
                        if (borders.length === 0) {
                            exePrs = { "border": "none" };
                        } else {
                            bsize = $_border_size.val();
                            bcolor = $_icon_color.css("background-color");
                            bcss = {};
                            for (i = 0, len = borders.length; i < len; ++i) {
                                bcss[borders[i] + "style"] = val;
                                bcss[borders[i] + "width"] = bsize;
                                bcss[borders[i] + "color"] = bcolor;
                            }
                            exePrs = { "border": bcss };
                        }
                        _this.paragraph(exePrs);
                    } else if (elId === "_border_size") {//边框大小
                        borders = getBodyprexFn();
                        if (borders.length === 0) {
                            exePrs = { "border": "none" };
                        } else {
                            bcolor = $_icon_color.css("background-color");
                            bstyle = $_border_style.val();
                            bcss = {};
                            for (i = 0, len = borders.length; i < len; ++i) {
                                bcss[borders[i] + "style"] = bstyle;
                                bcss[borders[i] + "width"] = val;
                                bcss[borders[i] + "color"] = bcolor;
                            }
                            exePrs = { "border": bcss };
                        }
                        _this.paragraph(exePrs);
                    }
                };
                $_line_height_.on("change", onSelectedFn);
                $_border_style.on("change", onSelectedFn);
                $_border_size.on("change", onSelectedFn);

                //边框位置 
                $("<span class='_border_pos' v='left'  style='border:1px dashed #CCCCCC;border-left:2px solid #0000FF;cursor:pointer; display:inline-block;width:15px;height:15px;margin-right:8px;'></span>").appendTo($_border_pos).click(posClickFn);
                $("<span class='_border_pos' v='top'  style='border:1px dashed #CCCCCC;border-top:2px solid #0000FF;cursor:pointer; display:inline-block;width:15px;height:15px;margin-right:8px;'></span>").appendTo($_border_pos).click(posClickFn);
                $("<span class='_border_pos' v='right' style='border:1px dashed #CCCCCC;border-right:2px solid #0000FF;cursor:pointer; display:inline-block;width:15px;height:15px;margin-right:8px;'></span>").appendTo($_border_pos).click(posClickFn);
                $("<span class='_border_pos' v='bottom' style='border:1px dashed #CCCCCC;border-bottom:2px solid #0000FF;cursor:pointer; display:inline-block;width:15px;height:15px;margin-right:8px;'></span>").appendTo($_border_pos).click(posClickFn);

                var ifrPos = _this[_this.windowName + "_iframe"].offset();
                var picker = _this[_this.windowName].data("colorPicker");
                picker.opts.positionFix = {
                    left: ifrPos.left + 4,
                    top: ifrPos.top + 4
                };
                //边框颜色
                $_icon_color.mousedown(function () {
                    picker.hideImd(true);
                    picker.setTarget($(this));
                    var borders = getBodyprexFn();
                    var bstyle = $_border_style.val();
                    var bsize = $_border_size.val();
                    picker.opts.change = function (hex, opacity) {
                        if (borders.length > 0) {
                            var bcss = {};
                            for (var i = 0, len = borders.length; i < len; ++i) {
                                bcss[borders[i] + "style"] = bstyle;
                                bcss[borders[i] + "width"] = bsize;
                                bcss[borders[i] + "color"] = hex;
                            }
                            var exePrs = { "border": bcss };
                            _this.paragraph(exePrs);
                        }
                    };
                    picker.setValue($(this).css("background-color"), false);
                });

                //背景色  _bg_color
                var $_bg_color = f.find("#_bg_color");
                $_bg_color.mousedown(function () {
                    picker.hideImd(true);
                    picker.setTarget($(this));

                    picker.opts.change = function (hex, opacity) {//注册颜色变化函数 
                        var exePrs = $.extend({}, prs);
                        exePrs["background-color"] = hex;
                        _this.paragraph(exePrs);
                    };
                    var bg = $(this).css("background-color");
                    picker.setValue(bg, false);
                    console.log("激活背景色");
                });

                //字体颜色
                var $_font_color = f.find("#_font_color");
                $_font_color.mousedown(function () {
                    picker.hideImd(true);
                    picker.setTarget($(this));
                    picker.opts.change = function (hex, opacity) {//注册颜色变化函数 
                        var exePrs = $.extend({}, prs);
                        exePrs["color"] = hex;
                        _this.paragraph(exePrs);
                    };
                    picker.setValue($(this).css("background-color"), false);
                });

                //是否阴影
                var $_shadow = f.find("#_shadow").on("click", function () {
                    var $box = $(this);
                    var exePrs = $.extend({}, prs);
                    if ($box.prop("checked")) {
                        exePrs["box-shadow"] = "0 3px 5px -1px rgba(0, 0, 0, .2), 0 6px 10px 0 rgba(0, 0, 0, .14), 0 1px 18px 0 rgba(0, 0, 0, .12)";
                    } else {
                        exePrs["box-shadow"] = "none";
                    }
                    _this.paragraph(exePrs);
                });

                f.find("button").click(function () {
                    _this.closeWindow();
                    _this.removeSectionResizeBar();
                });
                _this["paragrapForm"].data("form", {
                    indent: $_indent_,
                    top: $_margin_top_,
                    bottom: $_margin_bottom_,
                    left: $_padding_left_,
                    right: $_padding_right_,
                    lineHeight: $_line_height_,
                    borderPos: $_border_pos,
                    borderStyle: $_border_style,
                    borderColor: $_icon_color,
                    borderSize: $_border_size,
                    backgroundColor: $_bg_color,
                    fontColor: $_font_color,
                    shadow: $_shadow
                });
            }
            var colorPicker = _this[_this.windowName].data("colorPicker");
            var style = _this.getParagraphcss();
            var form = _this["paragrapForm"].data("form");

            //边框
            var border = style.border;
            var borderCss;
            form.borderPos.children().each(function () {
                var $o = $(this);
                if (border[$o.attr("v")]) {
                    $o.css("background-color", '#2EF5FF').addClass("_act");
                    borderCss = border[$o.attr("v")];
                } else {
                    $o.css("background-color", 'transparent').removeClass("_act");
                }
            });
            var fn1 = function (i, opt, prpName) {
                if (borderCss) {
                    if (borderCss[prpName] === opt.attr("value")) {
                        opt.prop("selected", true);
                    } else {
                        opt.prop("selected", false);
                    }
                } else {
                    if (i === 0) {
                        opt.prop("selected", true);
                    } else {
                        opt.prop("selected", false);
                    }
                }
            };
            form.borderStyle.children().each(function (i) {
                var opt = $(this);
                fn1(i, opt, "style");
            });
            form.borderSize.children().each(function (i) {
                var opt = $(this);
                fn1(i, opt, "width");
            });
            var trastColor;
            if (borderCss) {
                trastColor = colorPicker.getContrastColor(borderCss.color);
                form.borderColor.css({ "background-color": borderCss.color, "color": trastColor });
            } else {
                form.borderColor.css({ "background-color": "#666666", "color": "#ffffff" });
            }
            //边框结束
            //背景色
            var bgColor = style["background-color"];
            trastColor = colorPicker.getContrastColor(bgColor);
            form.backgroundColor.css({ "background-color": bgColor, "color": trastColor });
            //字体颜色
            var fontColor = style["color"];
            trastColor = colorPicker.getContrastColor(fontColor);
            form.fontColor.css({ "background-color": fontColor, "color": trastColor });

            form.indent.val(style.indent);
            form.top.val(style["margin-top"]);
            form.bottom.val(style["margin-bottom"]);

            form.left.val(style["padding-left"]);
            form.right.val(style["padding-right"]);
            style["line-height"] = style["line-height"] + "";
            form.lineHeight.children().each(function () {
                var opt = $(this);
                if (opt.attr("value") === style["line-height"]) {
                    opt.prop("selected", true);
                } else {
                    opt.prop("selected", false);
                }
            });

            body.append(_this["paragrapForm"]);
            _this.setSectionWidth(true);
        }
    }, params, this.setWindowColorPickerPosition);
    this.setWindowColorPickerPosition();
};
/**
 * 获取jq元素对象的边框
 * ***/
Kedit.prototype._getJqObjBorders = function (pele) {
    var borders = {};
    var bcolor = pele.css("border-top-color");
    var bwidth = pele.css("border-top-width");
    var bstyle = pele.css("border-top-style");
    if (bstyle !== "none") {
        borders["top"] = { color: bcolor, width: bwidth, style: bstyle };
    }

    bcolor = pele.css("border-right-color");
    bwidth = pele.css("border-right-width");
    bstyle = pele.css("border-right-style");
    if (bstyle !== "none") {
        borders["right"] = { color: bcolor, width: bwidth, style: bstyle };
    }

    bcolor = pele.css("border-bottom-color");
    bwidth = pele.css("border-bottom-width");
    bstyle = pele.css("border-bottom-style");
    if (bstyle !== "none") {
        borders["bottom"] = { color: bcolor, width: bwidth, style: bstyle };
    }

    bcolor = pele.css("border-left-color");
    bwidth = pele.css("border-left-width");
    bstyle = pele.css("border-left-style");
    if (bstyle !== "none") {
        borders["left"] = { color: bcolor, width: bwidth, style: bstyle };
    }
    return borders;
};
/**
 * 获取选区所在的段落样式
 * ****/
Kedit.prototype.getParagraphcss = function () {
    //console.log("getParagraphcss >>>");
    var css = {
        indent: undefined,
        "margin-top": undefined,
        "margin-bottom": undefined,
        "padding-left": undefined,
        "padding-right": undefined,
        "line-height": undefined,
        "background-color": undefined,
        "border": undefined,
        "color": undefined
    };
    var _this = this;
    this.foreachPTargets(function (pele, i) {
        if (!pele.hasClass("_exclude_")) {
            var borders = _this._getJqObjBorders(pele);
            css["border"] = borders;
            var children = pele.children();
            children.each(function () {
                if (this.tagName === "PRE") {
                    return true;
                }
                var $c = $(this);
                var color;
                if ($c[0].tagName === "TABLE") {
                    $c.find("td").each(function () {
                        var td = $(this);
                        color = td.css("color");
                        if (!css["color"]) {
                            css["color"] = color;
                        } else if (css["color"] !== color) {
                            css["color"] = "#666666";
                        }
                    });
                } else {
                    if ($c.children().length === 0) {
                        color = $c.css("color");
                        if (!css["color"]) {
                            css["color"] = color;
                        } else if (css["color"] !== color) {
                            css["color"] = "#666666";
                        }
                    }
                }
            });
            var backgroundColor = pele.css("background-color");
            if (!css["background-color"]) {
                css["background-color"] = backgroundColor;
            } else if (css["background-color"] !== backgroundColor) {
                css["background-color"] = undefined;
            }

            var text_indent = pele.css("text-indent");
            if (text_indent) {
                var firstFontSize = _this.getFirstCharFontSize(pele);
                text_indent = parseFloat(text_indent.replace("px", "")) / firstFontSize;
                if (!css["indent"]) {
                    css["indent"] = text_indent;
                } else if (css["indent"] !== text_indent) {
                    css["indent"] = "";
                }
            }
            var maxFs = _this._getParagraphMaxFontSize(pele);
            var line_height = (parseFloat(pele.css("line-height"), "") / maxFs).toFixed(1);
            //console.log("line_height === "+line_height);
            if (!css["line-height"]) {
                css["line-height"] = line_height;
            } else if (css["line-height"] !== line_height) {
                css["line-height"] = undefined;
            }
            var margin_top = parseInt(pele.css("margin-top"), "");
            if (!css["margin-top"]) {
                css["margin-top"] = margin_top;
            } else if (css["margin-top"] !== margin_top) {
                css["margin-top"] = "";
            }
            var margin_bottom = parseInt(pele.css("margin-bottom"), "");
            if (!css["margin-bottom"]) {
                css["margin-bottom"] = margin_bottom;
            } else if (css["margin-bottom"] !== margin_bottom) {
                css["margin-bottom"] = "";
            }
            var padding_left = parseInt(pele.css("padding-left"), "");
            if (!css["padding-left"]) {
                css["padding-left"] = padding_left;
            } else if (css["padding-left"] !== padding_left) {
                css["padding-left"] = "";
            }
            var padding_right = parseInt(pele.css("padding-right"), "");
            if (!css["padding-right"]) {
                css["padding-right"] = padding_right;
            } else if (css["padding-right"] !== padding_right) {
                css["padding-right"] = "";
            }
        }
    });
    //console.log(JSON.stringify(css));
    if (!css["color"]) {
        css["color"] = "#666666";
    }
    return css;
};
/**段落修饰**/
Kedit.prototype.paragraph = function (params) {
    var clear = false;
    var css = {};
    var firstCharSize = 14;
    var indent;
    if (typeof params["indent"] !== "undefined" && params["indent"] !== "") {
        indent = params["indent"];
    }
    if (typeof params["margin-top"] !== "undefined" && params["margin-top"] !== "") {
        css["margin-top"] = params["margin-top"] + "px";
    }
    if (typeof params["margin-bottom"] !== "undefined" && params["margin-bottom"] !== "") {
        css["margin-bottom"] = params["margin-bottom"] + "px";
    }

    if (typeof params["padding-left"] !== "undefined" && params["padding-left"] !== "") {
        css["padding-left"] = params["padding-left"] + "px";
    }
    if (typeof params["padding-right"] !== "undefined" && params["padding-right"] !== "") {
        css["padding-right"] = params["padding-right"] + "px";
    }
    var line_height;
    if (typeof params["line-height"] !== "undefined" && params["line-height"] !== "") {
        line_height = parseFloat(params["line-height"]);
    }
    if (typeof params["background-color"] !== "undefined" && params["background-color"] !== "") {
        css["background-color"] = params["background-color"];
    }
    if (typeof params["box-shadow"] !== "undefined" && params["box-shadow"] !== "") {
        css["box-shadow"] = params["box-shadow"];
    }

    var isBorder = false;
    //边框修饰
    if (typeof params["border"] !== "undefined") {
        isBorder = true;
        if ($.isPlainObject(params["border"])) {
            css = params["border"];
        } else {
            css = params;
        }
    }
    //console.log("paragraph >>>>> " + JSON.stringify(css));
    if (typeof params["color"] !== "undefined" && params["color"] !== "") {
        css["color"] = params["color"];
    }
    var _this = this;
    this.foreachPTargets(function (pele, i) {
        if (!pele.hasClass("_exclude_")) {
            if (typeof line_height !== "undefined") {
                var maxFs = _this._getParagraphMaxFontSize(pele);
                var lineHeight = line_height * maxFs;
                css["line-height"] = lineHeight + "px";
            }
            if (typeof indent !== "undefined") {
                firstCharSize = _this._getFirstCharFontSize(pele);
                var txtIndent = firstCharSize * indent;
                css["text-indent"] = txtIndent + "px";
            }
            if (!css["color"]) {
                if (isBorder) {
                    pele.css({ "border": "none" });
                }
                pele.css(css);
            }
            //对li 修饰行高
            if (css["line-height"]) {
                pele.find("li").css("line-height", css["line-height"]);
            } else if (css["background-color"] || css["color"]) {
                _this._css2pChildren(pele.children(), css);
            }
        }
    });
    if (clear) {
        this.startPElement = undefined;
        this.endPElement = undefined;
    }
};
/***
 * 段落修饰，修饰段落里的子元素
 * ***/
Kedit.prototype._css2pChildren = function (children, css) {
    var _this = this;
    children.each(function () {
        if (this.tagName === "PRE") {
            return true;
        }
        var $t = $(this);
        if (this.tagName === "SPAN" || this.tagName === "TD" || this.tagName === "P") {
            $t.css(css);
        }
        _this._css2pChildren($t.children(), css);
    });
};
/**
 * 插入浮动图片
 * ***/
Kedit.prototype.insertFloatImg = function () {
    var wrap = this._createFloatWindow(300, 230);
    var imgWrap = $("<div title='" + eConfig.label.dblUploadImg + "' class='k_box_size k_editor_float_img_wrap' style='width:100%;height:100%;position:absolute;z-index:20000001;background:none;top:0;left:0;'></div>");
    imgWrap.appendTo(wrap);
    $("<div style='width:100%;line-height:100px;text-align:center;font-weight:bold;font-size:1.2em;color:#A2A2A2;'>" + eConfig.label.dblUploadImg + "</div>").appendTo(imgWrap);
    this._bindFlowImgEvents(imgWrap);
};
Kedit.prototype._bindFlowImgEvents = function (imgWrap) {
    var _this = this;
    imgWrap.dblclick(function () {
        var $t = $(this);
        _this._floatImgWrap = $t;
        //创建隐藏的upload
        var body = _getBody();
        var uploadDiv = body.children("#editor_hidden_file_upload");
        if (uploadDiv.length === 0) {
            uploadDiv = $("<div id='editor_hidden_file_upload' style='position:absolute;z-index:-100;top:-100px;'></div>").appendTo(body);
            var uploadOpts = _this.opts.uploadImg;
            new $B.MutilUpload({
                target: uploadDiv,
                files: [{
                    name: '_k_edit_upolad_file',
                    type: '.png,.gif,.jpg,jpeg',
                    label: eConfig.label.selectImg,
                    must: true
                }],
                timeout: 190, //60秒钟超时             
                immediate: true, //选择文件后是否立即自动上传，即不用用户点击提交按钮就上传
                url: uploadOpts.url,
                success: function (res) { //成功时候的回调
                    //var target = _this._floatImgWrap;
                    var url = res.data;
                    if ($.isPlainObject(url)) {
                        url = res.data.url;
                    }
                    var zIndx = parseInt(_this._floatImgWrap.css("z-index"));
                    _this._floatImgWrap.html("<img src='" + url + "' style='width:100%;height:100%;position:relative;z-index:" + zIndx + "'/><div style='width:100%;height:100%;position:absolute;z-index:" + (zIndx + 1) + ";top:0;'></div>");
                    if (uploadOpts.onSuccess) {
                        uploadOpts.onSuccess.call(_this._floatImgWrap.children("img") ,res);
                    }
                },
                onselected: function () {
                    _this._floatImgWrap.html("<div style='width:100%;line-height:100px;text-align:center;font-weight:bold;font-size:1.2em;color:#A2A2A2;'><span style='color:#8E8E8E;font-size:1.2em;'><i style='color:#8E8E8E;font-size:1.2em;padding-right:6px;' class='fa fa-spinner fa-spin'></i>" + $B.config.uploading + "</span></div>");
                    return true;
                },
                error: function (res) { //错误回调
                    _this._floatImgWrap.html("<div style='width:100%;line-height:100px;text-align:center;font-weight:bold;font-size:1.2em;color:#A2A2A2;'><span style='color:#8E8E8E;font-size:1.2em;'><i style='color:#8E8E8E;font-size:1.2em;padding-right:6px;' class='fa fa-spinner'></i>" + eConfig.label.uploadError + "</span></div>");
                }
            });
        }
        uploadDiv.find(".k_visual_file_item_input").trigger("click");
    }).attr("title", eConfig.label.dblUploadImg);
};
Kedit.prototype.insertFloatText = function () {
    var wrap = this._createFloatWindow(300, 230);
    var id = getUUID();
    var input = $("<div spellcheck='false' id='" + id + "' class='k_box_size k_editor_float_input' contenteditable='true' style='padding:4px 5px;width:100%;height:100%;position:absolute;z-index:20000001;background:none;top:0;left:0;'></div>");
    input.appendTo(wrap);
    this.createPElement().appendTo(input).css("background", "none").children().each(function () {
        $(this).css("background", "none");
    });
    var _this = this;
    input.focus();
    _this.disabledFunc(eConfig.floatEidtor);
    _this._initInputEvents(input);
};
//打开图标窗口
Kedit.prototype.openIconWindow = function (method, params, $btn) {
    var _this = this;
    params["method"] = method;//
    this.openWindow({
        title: eConfig.label.insertIcon,
        width: 450,
        height: 300,
        contentFn: function (body, prs) {
            if (!_this["iconForm"]) {
                _this["iconForm"] = $("<div style='width:100%;height:100%;position:relative;' class='k_box_size'></div>");
                _this["iconForm"].append(eConfig.iconForm);
                _this["iconForm"].find("#_btn_").click(function () {
                    var canvas = _this["_icon_canvas"][0];
                    var dataURL = canvas.toDataURL("image/png");
                    console.log(dataURL);
                    _this.closeWindow();
                    prs.isIcon = true;
                    prs.icon = dataURL;
                    var w = _this["_icon_canvas"].width();
                    prs.width = w;
                    prs.height = w;
                    _this.emotion(prs);//走插入表情逻辑
                });
                var canvasWrap = $("<div style='position: absolute;right:0px;top:0px;width:50px;height:50px;'></div>").appendTo(_this["iconForm"]);
                _this["iconForm"].find("#_icons").children("span").click(function () {
                    var $s = $(this);
                    var font = $s[0].textContent;
                    var fontSize = parseInt(_this["iconForm"].find("#_tip_wrap").text().replace("px", ""));
                    var width = fontSize;
                    var height = width;
                    $s.css("color", "#FF8305").siblings().css("color", "#7E7E7E");
                    canvasWrap.children().remove();
                    var $canvas = $("<canvas id='myCanvas' width='" + width + "' height='" + height + "' style='border:1px solid #F7F7F7;'></canvas>").appendTo(canvasWrap);
                    var canvas = $canvas[0];
                    var context = canvas.getContext('2d');
                    context.fillStyle = '#7E7E7E';
                    context.font = fontSize + 'px fontello';
                    context.fillText(font, 0, height - 2, width);
                    $canvas.data("icon_data", {
                        "font-icon": font,
                        "color": '#7E7E7E',
                        "fontSize": fontSize
                    });
                    _this["_icon_canvas"] = $canvas;
                });
                var slider = _this["iconForm"].find("#_slider");
                var i1 = $("<i style='margin-right:10px;padding-top:4px;cursor:not-allowed;color:#D8D8D8;' class='fa  fa-fast-bw'></i>").appendTo(slider);
                var i2 = $("<i style='margin-right:10px;padding-top:4px;cursor:pointer;color:#7E7E7E;' class='fa  fa-fast-fw'></i>").appendTo(slider);
                i1.click(function () {
                    var $i = $(this);
                    var $txt = $i.parent().parent().next();
                    var srcV = parseInt($txt.text().replace("px", ""));
                    if (srcV === 12) {
                        return;
                    }
                    var v = srcV - 1;
                    if (v === 12) {
                        $i.css({
                            'cursor': 'not-allowed',
                            'color': '#D8D8D8'
                        });
                    }
                    if (v < 40) {
                        $i.next().css({
                            'cursor': 'pointer',
                            'color': '#7E7E7E'
                        });
                    }
                    $txt.text(v + "px");
                    var $canvas = _this["_icon_canvas"];
                    var canvas = $canvas[0];
                    var data = $canvas.data("icon_data");
                    var fontSize = v;
                    var context = canvas.getContext('2d');
                    canvas.height = fontSize;
                    canvas.width = fontSize;

                    context.fillStyle = data["color"];
                    context.font = fontSize + 'px fontello';

                    context.fillText(data["font-icon"], 0, canvas.height - 2, canvas.width);

                    $canvas.data("icon_data", {
                        "font-icon": data["font-icon"],
                        "color": data["color"],
                        "fontSize": fontSize
                    });

                });
                i2.click(function () {
                    var $i = $(this);
                    var $txt = $i.parent().parent().next();
                    var srcV = parseInt($txt.text().replace("px", ""));
                    if (srcV === 40) {
                        return;
                    }
                    var v = srcV + 1;
                    if (v === 40) {
                        $i.css({
                            'cursor': 'not-allowed',
                            'color': '#D8D8D8'
                        });
                    }
                    if (v > 12) {
                        $i.prev().css({
                            'cursor': 'pointer',
                            'color': '#7E7E7E'
                        });
                    }
                    $txt.text(v + "px");
                    var $canvas = _this["_icon_canvas"];
                    var canvas = $canvas[0];
                    var data = $canvas.data("icon_data");
                    var fontSize = v;
                    var context = canvas.getContext('2d');
                    canvas.height = fontSize;
                    canvas.width = fontSize;

                    context.fillStyle = data["color"];
                    context.font = fontSize + 'px fontello';

                    context.fillText(data["font-icon"], 0, canvas.height - 2, canvas.width);

                    $canvas.data("icon_data", {
                        "font-icon": data["font-icon"],
                        "color": data["color"],
                        "fontSize": fontSize
                    });
                });
                _this._createWindowColorPicker();
            }
            body.append(_this["iconForm"]);
            var $color = _this["iconForm"].find("#icon_color");
            var ifrPos = _this[_this.windowName + "_iframe"].offset();
            var picker = _this[_this.windowName].data("colorPicker");
            picker.unbindTarget();
            picker.opts.positionFix = {
                left: ifrPos.left + 4,
                top: ifrPos.top + 4
            };
            picker.setTarget($color).setValue('#7E7E7E');
            picker.opts.change = function (hex, opacity) {//注册颜色变化函数              
                if (_this["_icon_canvas"]) {
                    var canvas = _this["_icon_canvas"][0];
                    var data = _this["_icon_canvas"].data("icon_data");
                    var fontSize = data.fontSize;
                    var context = canvas.getContext('2d');
                    canvas.height = fontSize;
                    canvas.width = fontSize;
                    context.fillStyle = hex;
                    context.font = fontSize + 'px fontello';
                    context.fillText(data["font-icon"], 0, canvas.height - 2, canvas.width);
                    _this["_icon_canvas"].data("icon_data", {
                        "font-icon": data["font-icon"],
                        "color": hex,
                        "fontSize": fontSize
                    });
                }
            };
            setTimeout(function () {
                _this["iconForm"].find("#_icons").children("span").first().trigger("click");
            }, 1000);
        }
    }, params, this.setWindowColorPickerPosition);
    this.setWindowColorPickerPosition();
};
Kedit.prototype.showEmotionWindow = function (params, $btn) {
    this.openEmotionWindow("emotion", params, $btn);
};
Kedit.prototype.openEmotionWindow = function (method, params, $btn) {
    var _this = this;
    params["method"] = method;
    this.openWindow({
        title: eConfig.label.insertEmotion,
        width: 450,
        height: 200,
        contentFn: function (body, prs) {
            if (!_this["emotionForm"]) {
                _this["emotionForm"] = $("<div style='width:100%;height:100%;' class='k_box_size'></div>");
                if (typeof window.kemConfig !== 'undefined') {
                    var keys = Object.keys(window.kemConfig);
                    var closerTimer;
                    var _clickFn = function () {
                        clearTimeout(closerTimer);
                        var gif = $(this).attr("_gif");
                        prs["gif"] = gif;
                        var mName = params["method"];
                        _this.execute(mName, params);
                        closerTimer = setTimeout(function () {
                            _this.closeWindow();
                        }, 1500);
                    };
                    for (var i = 1, len = keys.length; i <= len; ++i) {
                        $("<div _gif='" + i + "' style='cursor:pointer;margin:4px;float:left;width:24px;height:24px;background:url(" + window.kemConfig[i] + ")'></div>")
                            .appendTo(_this["emotionForm"]).click(_clickFn);
                    }
                }
            }
            body.append(_this["emotionForm"]);
        }
    }, params);
};
Kedit.prototype.openCodeWindow = function (method, params) {
    var _this = this;
    params["method"] = method;
    var $b = _getBody();
    var w = $b.width() * 0.8;
    var h = $b.height() * 0.7;
    this.openWindow({
        title: eConfig.label.insertCode,
        width: w,
        height: h,
        contentFn: function (body, prs) {
            if (!_this["codeForm"]) {
                _this["codeForm"] = $(eConfig.codeForm);
                var $txt = _this["codeForm"].find("#k_code_input");
                _this["codeForm"].find("button").click(function () {
                    var v = $txt.html();
                    var preTag = _this["codeForm"].data("sourceTag");
                    if (preTag) {//执行更新                               
                        if ($.trim(v) === "") {
                            var $span = preTag.parent();
                            preTag.remove($span);
                            _this.moveToEnd();
                        } else {
                            preTag.html(v);
                        }
                        _this["codeForm"].removeData("sourceTag");
                    } else {//执行插入
                        prs["code"] = v;
                        var mName = params["method"];
                        _this.execute(mName, prs);
                    }
                    _this.closeWindow();
                });
                //动态加载脚本
                setTimeout(function () {
                    var $b = _this["codeForm"].parent();
                    var win = _this["window_iframe"][0].contentWindow;
                    var doc = $b[0].ownerDocument;
                    initCodeEditor(win, doc);
                }, 100);
            }
            var s = "<div>\u200B</div>";
            if (prs["sourceTag"]) {
                s = prs["sourceTag"].html();
                _this["codeForm"].data("sourceTag", prs["sourceTag"]);
                prs["sourceTag"] = undefined;
            } else {
                _this["codeForm"].removeData("sourceTag");
            }
            _this["codeForm"].find("#k_code_input").html(s);
            body.append(_this["codeForm"]);
        }
    }, params);
};
Kedit.prototype.openMapWindow = function (method, params, $btn) {
    var _this = this;
    var opts = eConfig.map;
    params["method"] = method;
    var mapPage = opts.page;
    this.openPageWindow({
        title: eConfig.label.insertMap,
        width: opts.windowSize.width,
        height: opts.windowSize.height,
        contentFn: function (body, prs, doc) {
            _this["mapForm"] = body;
            _this["pageWindow_iframe"].off("load");
            _this["pageWindow_iframe"].on("load", function () {
                _this["pageWindow_iframe"][0].contentWindow.setEdit(_this);
            });
            doc.location.href = mapPage;
        }
    }, params);
};
Kedit.prototype.showInsertFileWindow = function (params, $btn) {
    this.openInsertFileWindow("upload", params, $btn);
};
Kedit.prototype.openInsertFileWindow = function (method, params, $btn) {
    var _this = this;
    var opts = this.opts.uploadFile;
    if (!opts || !opts.url) {
        $B.message("please set the args [uploadFile] ");
        return;
    }
    params["method"] = method;
    this.openWindow({
        title: eConfig.label.insertFile,
        width: 500,
        height: 230,
        contentFn: function (body, prs) {
            if (!_this["fileForm"]) {
                _this["fileForm"] = $(eConfig.fileForm);
                _this["fileForm"].children("div").first().children("a").click(function () {
                    var $t = $(this);
                    var id = $t.attr("id");
                    var sibs = $t.parent().siblings("table").hide();
                    sibs.filter("#" + id + "form").show();
                    $t.siblings().css({
                        "color": "#666",
                        "background": "#fff"
                    });
                    $t.css({
                        "color": "#fff",
                        "background": "#666"
                    });
                });
                var inputWrap = _this["fileForm"].find("#_file_upload_wrap");
                var successFn = function (res) {
                    var params = _this["fileForm"].data("params");
                    var linkName = _this["fileForm"].find("#_link_name_").val();
                    if (res.data["linkName"] && linkName === "") {
                        linkName = res.data["linkName"];
                    }
                    params["linkName"] = linkName;
                    var url;
                    if ($.isPlainObject(res.data)) {
                        url = res.data.url;
                    } else {
                        url = res.data;
                    }
                    params["url"] = url;
                    _this.closeWindow();
                    var mName = params["method"];
                    var $a = _this.execute(mName, params);
                    if (opts.onSuccess) {
                        opts.onSuccess.call($a ,res);
                    }
                };
                var uploadCfg = {
                    target: inputWrap,
                    timeout: 200,
                    canDelete: true,
                    deleteClearFile: true,
                    url: undefined,
                    files: [{
                        name: '_k_edit_upolad_file',
                        type: '.*',
                        label: eConfig.label.selectFile
                    }],
                    immediate: false,
                    success: successFn,
                    onselected: function (srcFileName, name, accept) {
                        var nameInput = _this["fileForm"].find("#_link_name_");
                        if (nameInput.val() === "") {
                            nameInput.val(srcFileName);
                        }
                        return true;
                    },
                    error: opts.onError
                };
                uploadCfg.url = opts.url;
                if (opts.label) {
                    uploadCfg.files[0].label = opts.label;
                }
                if (opts.setParams) {
                    uploadCfg.setParams = opts.setParams;
                }
                var uploadObj = new $B.MutilUpload(uploadCfg);
                _this["fileForm"].data("uploadObj", uploadObj);
                _this["fileForm"].find("#_submit_upload_").click(function () {
                    var $btn = $(this);
                    var local = $btn.parent().siblings("#_local_upload_form");
                    if (local.css("display") === "table") {
                        $btn.data("uploadObj").submit();
                    } else {
                        var url = _this["fileForm"].find("#_addr_url").val();
                        if (url.indexOf("http") < 0) {
                            url = "http://" + url;
                        }
                        successFn({
                            data: {
                                url: url
                            }
                        });
                    }
                }).data("uploadObj", uploadObj);
            }
            _this["fileForm"].data("params", prs);
            body.append(_this["fileForm"]);
            var uploadTab = _this["fileForm"].children().first().children("#_local_upload_").trigger("click");
            _this["fileForm"].data("uploadObj").reset();
            _this["fileForm"].find("#_addr_url").val('');
            _this["fileForm"].find("#_link_name_").val('');
        }
    }, params);
};
Kedit.prototype.showInsertImageWindow = function (params, $btn) {
    this.openInsertImageWindow("picture", params, $btn);
};
Kedit.prototype.openInsertImageWindow = function (method, params, $btn) {
    var _this = this;
    var opts = this.opts.uploadImg;
    if (!opts || !opts.url) {
        $B.message("please set the args [uploadImg] ");
        return;
    }
    params["method"] = method;
    this.openWindow({
        title: eConfig.label.insertImage,
        width: 500,
        height: 310,
        contentFn: function (body, prs) {
            if (!_this["imageForm"]) {
                _this["imageForm"] = $(eConfig.imageForm);
                _this["imageForm"].children("div").first().children("a").click(function () {
                    var $t = $(this);
                    var id = $t.attr("id");
                    var sibs = $t.parent().siblings("table").hide();
                    sibs.filter("#" + id + "form").show();
                    $t.siblings().css({
                        "color": "#666",
                        "background": "#fff"
                    });
                    $t.css({
                        "color": "#fff",
                        "background": "#666"
                    });
                });
                _this["$imgPosition"] = _this["imageForm"].find("#_img_pos");
                _this["$imgWidth"] = _this["imageForm"].find("#_img_width");
                _this["$imgHeight"] = _this["imageForm"].find("#_img_height");
                _this["$autowidth"] =_this["imageForm"].find("#autowidth").click(function(){
                    var isChked = $(this).prop("checked");
                    if(isChked){
                        _this["$imgHeight"].attr("disabled","disabled").addClass("disabled_text_color");
                        _this["$imgWidth"].attr("disabled","disabled").addClass("disabled_text_color");
                    }else{
                        _this["$imgHeight"].removeAttr("disabled").removeClass("disabled_text_color");
                        _this["$imgWidth"].removeAttr("disabled").removeClass("disabled_text_color");
                    }
                });
                var as = _this["imageForm"].find(".k_edit_img_layout").children("a").click(function () {
                    var $t = $(this);
                    $t.siblings().removeClass("k_edit_img_pos_actived");
                    $t.addClass("k_edit_img_pos_actived");
                    _this["$imgPosition"].val($t.attr("v"));
                });
                _this["imagePosAct"] = as.eq(1);
                var inputWrap = _this["imageForm"].find("#_file_upload_wrap");

                var _rightPadding = _this["imageForm"].find("#_right_k_padding");
                var _topPadding = _this["imageForm"].find("#_top_k_padding");
                var _bottomPadding = _this["imageForm"].find("#_bottom_k_padding");
                var _leftPadding = _this["imageForm"].find("#_left_k_padding");
                var successFn = function (res) {
                    var params = _this["imageForm"].data("params");
                    var url;
                    if ($.isPlainObject(res.data)) {
                        url = res.data.url;
                    } else {
                        url = res.data;
                    }
                    params["url"] = url;
                    params["width"] = _this["$imgWidth"].val();
                    params["height"] = _this["$imgHeight"].val();
                    if (res.data["width"] && params["width"] === "") {
                        params["width"] = res.data["width"];
                    }
                    if (res.data["height"] && params["height"] === "") {
                        params["height"] = res.data["height"];
                    }
                    params["position"] = _this["$imgPosition"].val();
                    params["right"] = _rightPadding.val();
                    params["top"] = _topPadding.val();
                    params["bottom"] = _bottomPadding.val();
                    params["left"] = _leftPadding.val();
                    params["link"] = _this["imageForm"].find("#_href_").val();
                    params["isAuto"] =  _this["$autowidth"].prop("checked");
                    _this.closeWindow();
                    var mName = params["method"];
                    //console.log(params);
                    var $img = _this.execute(mName, params);
                    if (opts.onSuccess) {
                        opts.onSuccess.call($img,res);
                    }
                };
                var uploadCfg = {
                    target: inputWrap,
                    timeout: 200, //超时时间 秒
                    canDelete: true, //是否可以动态删除
                    deleteClearFile: true, //删除时候只清除文件
                    url: undefined,
                    // 待上传的文件列表，用于设置input的 name 以在服务器区分文件  	
                    files: [{
                        name: '_k_edit_upolad_file',
                        type: '.png,.gif,.jpg,jpeg',
                        label: eConfig.label.selectImg,
                        must: true
                    }],
                    onselected: function (value, id, accept) {
                        return true;
                    }, //选择文件后的事件请返回true 以便通过验证
                    immediate: false, //选择文件后是否立即自动上传，即不用用户点击提交按钮就上传
                    success: successFn,
                    error: opts.onError
                };
                uploadCfg.url = opts.url;
                if (opts.label) {
                    uploadCfg.files[0].label = opts.label;
                }
                if (opts.setParams) {
                    uploadCfg.setParams = opts.setParams;
                }
                var uploadObj = new $B.MutilUpload(uploadCfg);
                _this["imageForm"].data("uploadObj", uploadObj);
                _this["imageForm"].find("#_submit_upload_").click(function () {
                    var $btn = $(this);
                    var local = $btn.parent().siblings("#_local_upload_form");
                    if (local.css("display") === "table") {
                        $btn.data("uploadObj").submit();
                    } else {
                        var url = _this["imageForm"].find("#_addr_url").val();
                        if (url.indexOf("http") < 0) {
                            url = "http://" + url;
                        }
                        successFn({
                            data: {
                                url: url
                            }
                        });
                    }
                }).data("uploadObj", uploadObj);
            }
            var mName = prs["method"];
            _this["imageForm"].data("params", prs);
            _this["imagePosAct"].trigger("click");
            _this["imageForm"].data("uploadObj").reset();
            body.append(_this["imageForm"]);
            var uploadTab = _this["imageForm"].children().first().children("#_local_upload_").trigger("click");
            var uploadWrap = _this["imageForm"].find("#_local_upload_form");
            var _$right = _this["imageForm"].find("#_right_k_padding");
            var _$top = _this["imageForm"].find("#_top_k_padding");
            var _$bottom = _this["imageForm"].find("#_bottom_k_padding");
            var _$left = _this["imageForm"].find("#_left_k_padding");
            var alignAs = _this["imageForm"].find(".k_edit_img_layout").children("a");
            var hidePos = _this["imageForm"].find("#_img_pos");
            var linkAtrr = _this["imageForm"].find("#_href_");
            linkAtrr.val("");
            _this["$imgHeight"].removeAttr("disabled").removeClass("disabled_text_color");
            _this["$imgWidth"].removeAttr("disabled").removeClass("disabled_text_color");
            _this["$autowidth"].prop("checked",false);
            if (mName === "updateImage") { //更新
                var $img = prs.$img; 
                var imgCss = _this._style2CssObject($img);
                if(imgCss.width === "100%"){
                    _this["$autowidth"].prop("checked",true);
                    _this["$imgHeight"].addClass("disabled_text_color").prop("disabled",true);
                    _this["$imgWidth"].addClass("disabled_text_color").prop("disabled",true);
                }
                linkAtrr.val(prs.$img.attr("link"));
                alignAs.last().hide();
                uploadTab.next().hide();
                uploadTab.text(eConfig.label.imgUpdate);
                uploadWrap.hide();                              
                // _this["$imgPosition"].parent().hide();
                if(prs["$img"]){
                    _this["$imgWidth"].val(prs["$img"].width());
                    _this["$imgHeight"].val(prs["$img"].height());
                }else{
                    _this["$imgWidth"].val("");
                    _this["$imgHeight"].val("");
                }               
                var margins = prs["margin"].replace(/px/g, "").split(/\s+/);
                var _top = margins[0];
                var _right, _buttom, _left;
                if (margins.length === 1) {
                    _right = _top,
                        _buttom = _top,
                        _left = _top;
                } else if (margins.length === 2) {
                    _right = margins[1],
                        _buttom = _top,
                        _left = margins[1];
                } else {
                    _right = margins[1],
                        _buttom = margins[2],
                        _left = margins[3];
                }
                _$top.val(_top);
                _$right.val(_right);
                _$bottom.val(_buttom);
                _$left.val(_left);
                var align = prs["text-align"];
                alignAs.each(function () {
                    var $a = $(this);
                    var v = $a.attr("v");
                    if (v === align) {
                        $a.addClass("k_edit_img_pos_actived");
                        hidePos.val(v);
                    } else {
                        $a.removeClass("k_edit_img_pos_actived");
                    }
                });
            } else {
                alignAs.last().show();
                alignAs.each(function () {
                    var $a = $(this);
                    var v = $a.attr("v");
                    if (v === "left") {
                        hidePos.val("left");
                        $a.addClass("k_edit_img_pos_actived");
                    } else {
                        $a.removeClass("k_edit_img_pos_actived");
                    }
                });
                uploadTab.next().show();
                uploadTab.text(eConfig.label.localUplod);
                uploadWrap.show();
                // _this["$imgPosition"].parent().show();
                _this["$imgWidth"].val('');
                _this["$imgHeight"].val('');
                _$right.val(2);
                _$left.val(2);
                _$top.val(4);
                _$bottom.val(4);
            }
        }
    },
        params
    );
};
Kedit.prototype.showUploadVideo = function (method, params, $btn) {
    this.openUploadVideoWindow("uploadVideo", params);
};
Kedit.prototype.openUploadVideoWindow = function (method, params, $btn) {
    if (typeof videojs !== "function") {
        $B.alert(eConfig.label.videoWarning);
        return;
    }
    var _this = this;
    var opts = this.opts.uploadVideo;
    if (!opts || !opts.url) {
        $B.message("please set the args [uploadVideo] ");
        return;
    }
    params["method"] = method;
    this.openWindow({
        title: eConfig.label.insertVideo,
        width: 500,
        height: 280,
        contentFn: function (body, prs) {
            if (!_this["videoForm"]) {
                _this["videoForm"] = $(eConfig.videoForm);
                _this["videoForm"].children("div").first().children("a").click(function () {
                    var $t = $(this);
                    var id = $t.attr("id");//
                    if ("_remote_upload_" === id) {
                        _this["videoForm"].find("#_is_real_video").show();
                    } else {
                        _this["videoForm"].find("#_is_real_video").hide();
                    }
                    var sibs = $t.parent().siblings("table").hide();
                    sibs.filter("#" + id + "form").show();
                    $t.siblings().css({
                        "color": "#666",
                        "background": "#fff"
                    });
                    $t.css({
                        "color": "#fff",
                        "background": "#666"
                    });
                });
                _this["$videoWidth"] = _this["videoForm"].find("#_video_width");
                _this["$videoHeight"] = _this["videoForm"].find("#_video_height");
                var isPureVideoInput = _this["videoForm"].find("#_video_is");
                var inputWrap = _this["videoForm"].find("#_video_upload_wrap");
                var _rightPadding = _this["videoForm"].find("#_right_v_padding");
                var _topPadding = _this["videoForm"].find("#_top_v_padding");
                var _bottomPadding = _this["videoForm"].find("#_bottom_v_padding");
                var _leftPadding = _this["videoForm"].find("#_left_v_padding");
                var _repeat = _this["videoForm"].find("#_video_repeat");
                _this["videoForm"].find("#_addr_video").on("input", function () {
                    var $i = $(this);
                    var _v = $i.val().toLowerCase();
                    if (/\.(mp4|flv|f4v|ogv|webm)$/.test(_v)) {
                        isPureVideoInput.prop("checked", true);
                    } else {
                        isPureVideoInput.prop("checked", false);
                    }
                });
                var successFn = function (res) {
                    var params = _this["videoForm"].data("params");
                    var url;
                    if ($.isPlainObject(res.data)) {
                        url = res.data.url;
                    } else {
                        url = res.data;
                    }
                    if (res.message && res.message !== "") {
                        $B.success(res.message, 1.5);
                    }
                    params["data"] = url;
                    params["repeat"] = _repeat.prop("checked");
                    params["width"] = _this["$videoWidth"].val();
                    params["height"] = _this["$videoHeight"].val();
                    params["ispure"] = isPureVideoInput.prop("checked");
                    if (res.data["width"] && params["width"] === "") {
                        params["width"] = res.data["width"];
                    }
                    if (res.data["height"] && params["height"] === "") {
                        params["height"] = res.data["height"];
                    }
                    params["right"] = _rightPadding.val();
                    params["top"] = _topPadding.val();
                    params["bottom"] = _bottomPadding.val();
                    params["left"] = _leftPadding.val();
                    _this.closeWindow();
                    var mName = params["method"];
                    var $v = _this.execute(mName, params);
                    if (opts.onSuccess) {
                        opts.onSuccess.call($v,res);
                    }
                };
                var uploadCfg = {
                    target: inputWrap,
                    timeout: 200, //超时时间 秒
                    canDelete: true, //是否可以动态删除
                    deleteClearFile: true, //删除时候只清除文件
                    url: undefined,
                    // 待上传的文件列表，用于设置input的 name 以在服务器区分文件  	
                    files: [{
                        name: '_k_edit_upolad_file',
                        type: '.flv,.f4v,.mp4,.ogv,.webm',
                        label: eConfig.label.selectVideo,
                        must: true
                    }],
                    onselected: function (value, id, accept) {
                        return true;
                    }, //选择文件后的事件请返回true 以便通过验证
                    immediate: false, //选择文件后是否立即自动上传，即不用用户点击提交按钮就上传
                    success: successFn,
                    error:opts.onError
                };
                uploadCfg.url = opts.url;
                if (opts.label) {
                    uploadCfg.files[0].label = opts.label;
                }
                if (opts.setParams) {
                    uploadCfg.setParams = opts.setParams;
                }
                var uploadObj = new $B.MutilUpload(uploadCfg);
                _this["videoForm"].data("uploadObj", uploadObj);
                _this["videoForm"].find("#_submit_upload_").click(function () {
                    var $btn = $(this);
                    var local = $btn.parent().siblings("#_local_upload_form");
                    if (local.css("display") === "table") {
                        $btn.data("uploadObj").submit();
                    } else {
                        var url = _this["videoForm"].find("#_addr_video").val();
                        if (url.indexOf("http") < 0) {
                            url = "http://" + url;
                        }
                        successFn({
                            data: {
                                url: url
                            }
                        });
                    }
                }).data("uploadObj", uploadObj);
            }
            var mName = prs["method"];
            _this["videoForm"].data("params", prs);
            _this["videoForm"].data("uploadObj").reset();
            body.append(_this["videoForm"]);
            var uploadTab = _this["videoForm"].children().first().children("#_local_upload_").trigger("click");
            var uploadWrap = _this["videoForm"].find("#_local_upload_form");
            var _$right = _this["videoForm"].find("#_right_v_padding");
            var _$top = _this["videoForm"].find("#_top_v_padding");
            var _$bottom = _this["videoForm"].find("#_bottom_v_padding");
            var _$left = _this["videoForm"].find("#_left_v_padding");
            if (mName === "updateVideo") { //更新
                uploadTab.next().hide();
                uploadTab.text(eConfig.label.videoUpdate);
                uploadWrap.hide();
                _this["$videoWidth"].val(prs["width"]);
                _this["$videoHeight"].val(prs["height"]);
                var margins = prs["margin"].replace(/px/g, "").split(/\s+/);
                var _top = margins[0];
                var _right, _buttom, _left;
                if (margins.length === 1) {
                    _right = _top,
                        _buttom = _top,
                        _left = _top;
                } else if (margins.length === 2) {
                    _right = margins[1],
                        _buttom = _top,
                        _left = margins[1];
                } else {
                    _right = margins[1],
                        _buttom = margins[2],
                        _left = margins[3];
                }
                _$top.val(_top);
                _$right.val(_right);
                _$bottom.val(_buttom);
                _$left.val(_left);
            } else {
                uploadTab.next().show();
                uploadTab.text(eConfig.label.localUplod);
                uploadWrap.show();
                _this["$videoWidth"].val('');
                _this["$videoHeight"].val('');
                _$right.val(2);
                _$left.val(2);
                _$top.val(4);
                _$bottom.val(4);
            }
        }
    },
        params
    );
};
Kedit.prototype.updateVideo = function (params) {
    var $pre = params.$pre;
    var bottom = params.bottom;
    var top = params.top;
    var left = params.left;
    var right = params.right;
    var data = JSON.parse($pre.attr("data"));
    data.loop = params.repeat;
    data.height = parseInt(data.height);
    data.width = parseInt(data.width);
    var margin = [top + "px", right + "px", bottom + "px", left + "px"];
    $pre.css("margin", margin.join(" "));
    if (data.width !== params.width || data.height !== params.height) {
        data.width = params.width;
        data.height = params.height;
        if ($pre.hasClass("k_video_url")) {
            $pre.children("div").css({ width: data.width, height: data.height });
        } else {
            var player = $pre.data("player");
            player.width(data.width);
            player.height(data.height);
        }
    }
    if (!$pre.hasClass("k_video_url")) {
        $pre.attr("data", JSON.stringify(data));
    }
};
/***
 * finished 2019-02-25 23:00
 * 上传视频支持：依赖videojs，支持本地视频、远程视频（iframe页面/纯视频ur）
 * params = {
 *      width : 视频宽度
 *      height: 视频高度
 *      repeat : 是否循环播放
 *      ispure : 纯视频url(即非网页嵌入式视频)
 *      data：url / 数组[{ url: xxx ,type: video/mp4 }]
 * }
 * ****/
Kedit.prototype.uploadVideo = function (params) {
    var range = this.range;
    if (!range) {
        return;
    }
    var id = getUUID();
    var width = params.width === "" ? 320 : params.width,
        height = params.height === "" ? 240 : params.height;
    if (params.top === "") {
        params.top = 2;
    }
    if (params.right === "") {
        params.right = 2;
    }
    if (params.bottom === "") {
        params.bottom = 2;
    }
    if (params.left === "") {
        params.left = 2;
    }
    var margin = {
        "margin-top": params.top + "px",
        "margin-right": params.right + "px",
        "margin-bottom": params.bottom + "px",
        "margin-left": params.left + "px"
    };
    var videoParams = {
        muted: true,
        controls: true,
        height: height,
        width: width,
        loop: params.repeat
    };
    var $ifr;
    var insertTag = this._getInsertP();
    insertTag.children().remove();
    var $video, nextPelement, videoHtml, isVideoJs = false;
    var source = [];
    if ($.isArray(params.data)) {//本地上传
        isVideoJs = true;
        var videoUrl;
        for (var i = 0, len = params.data.length; i < len; ++i) {
            if (!videoUrl) {
                videoUrl = params.data[i].url;
            }
            source.push('<source src="' + params.data[i].url + '" type="' + params.data[i].type + '"></source>');
        }
        videoHtml = eConfig.videoHtml.replace(/_\$video_url\$_/g, videoUrl).replace("my_video_id", id).replace("_$source$_", source.join(""));
    } else {//url方式
        var ispure = params.ispure;
        if (ispure) {
            var videoType;
            var vurl = params.data.toLowerCase();
            if (vurl.indexOf(".mp4") > 0) {
                videoType = 'video/mp4';
            } else if (vurl.indexOf(".ogg") > 0) {
                videoType = 'video/ogg';
            } else if (vurl.indexOf(".webm") > 0) {
                videoType = 'video/webm';
            }
            if (!videoType) {
                $B.alert("not support type!");
                return;
            }
            isVideoJs = true;
            videoUrl = params.data;
            source.push('<source src="' + videoUrl + '" type="' + videoType + '"></source>');
            videoHtml = eConfig.videoHtml.replace(/_\$video_url\$_/g, videoUrl).replace("my_video_id", id).replace("_$source$_", source.join(""));
        } else {
            var remotePre = $('<pre contenteditable="false" style="padding: 1px; margin:2px;" class="k_video_pre k_video_url"><div class="k_video_ifr_wrap" style="overflow:hidden;"><iframe scrolling="no" class="panel_content_ifr" frameborder="0" style="overflow:visible;height:100%;width:100%;display:block;vertical-align:top;" ></iframe></div></pre>');
            $ifr = remotePre.children("div").css({
                width: width,
                height: height,
                'padding-top': margin["margin-top"],
                'padding-right': margin["margin-right"],
                'padding-bottom': margin["margin-bottom"],
                'padding-left': margin["margin-left"]
            }).children("iframe");
            videoHtml = remotePre[0].outerHTML;
        }
    }
    if (this.clickActivedObject && this.clickActivedObject.className === "table") {
        var createNextPle = false;
        var clickTd = this.clickActivedObject.clickTd;
        if (!clickTd && this.range) {
            var acontainer = this.range.commonAncestorContainer;
            if (acontainer.nodeType === 3) {
                acontainer = $(acontainer.parentNode);
            } else {
                acontainer = $(acontainer);
            }
            while (acontainer.length > 0) {
                if (acontainer[0].tagName === "TD") {
                    clickTd = acontainer;
                    break;
                }
                acontainer = acontainer.parent();
            }
        }
        if (clickTd) {//插入表格td中                    
            clickTd.html(videoHtml);
            this.clickActivedObject.reSize();
            this.clickActivedObject.reSize(true);//设置大小 
            $video = clickTd.children("pre");
        }
    } else {
        createNextPle = true;
        insertTag.append(videoHtml);
        $video = insertTag.children("pre");
    }
    if (isVideoJs) {
        $video.css(margin);
        this._createVideoPlayer($video, videoParams);
    } else {
        $ifr = $video.find("iframe");
        var ifr = $ifr[0];
        ifr.src = params.data;
    }
    if (createNextPle) {
        nextPelement = insertTag.next();
        if (nextPelement.length === 0) {
            nextPelement = this.insertPElement();
        }
    }
    var _this = this;
    setTimeout(function () {
        _this._bindVideoEvents($video);
        if (nextPelement) {
            _this.moveToEnd(nextPelement);
        }
    }, 10);
    return $video;
};
/**
* 创建videojs的 player
* **/
Kedit.prototype._createVideoPlayer = function ($preJq, videoParams) {
    if ($preJq.length === 0 || $preJq[0].tagName !== "PRE") {
        return;
    }
    var domEl = $preJq.children(".video-js");
    var id, videoEl;
    if (domEl.length === 1 && domEl[0].tagName === "DIV") {//移除
        videoEl = domEl.children("video");
        videoEl.detach().insertAfter(domEl);
        domEl.remove();
        id = videoEl.attr("id");
    } else if (domEl[0].tagName === "VIDEO") {
        id = domEl.attr("id");
        videoEl = domEl;
    }
    id = id.replace("_html5_api", "");
    videoEl.attr("id", id);
    var prop = $preJq.attr("data");
    if (prop) {
        prop = prop.replace(/&quot;/g, "\"");
        videoEl.attr("data-setup", prop);
    }
    videoEl.addClass("video-js vjs-default-skin vjs-big-play-centered");
    var video = window["videojs"];
    //避免重复创建时候 存在相同的video实例
    var players = video.getPlayers();
    if (players) {
        for (var p in players) {
            if (players.hasOwnProperty(p) && p === id) {
                delete players[p];
            }
        }
    }
    $preJq.attr("data", JSON.stringify(videoParams));
    var player = video(id, videoParams);
    $preJq.data("player", player);
};
/***
* 绑定视频事件
* ***/
Kedit.prototype._bindVideoEvents = function (el) {
    var _this = this;
    var $video;
    var firstEl = el.children().first();
    if (firstEl[0].tagName === "VIDEO") {
        $video = firstEl;
    } else {
        if (firstEl.hasClass("video-js")) {
            $video = firstEl.children("video");
        } else {
            $video = el;//frame嵌入的视频,只能操作pre元素，
        }
    }
    //兼容外部插入视频场景           
    $video.mouseup(function (e) {
        if (e.which === 3) {
            var $t = $(this);
            var self = $t.parent();
            if (self[0].tagName === "DIV" && !self.hasClass("_section_div_")) {
                self = self.parent();
            }
            var pEl = self;
            if (!self.hasClass("_section_div_")) {
                pEl = self.parent();
            }
            while (pEl.length > 0) {
                if (pEl[0].tagName === "DIV") {
                    break;
                }
                pEl = pEl.parent();
            }
            var me = _this;
            me.startPElement = pEl;
            me.endPElement = pEl;
            me.openTIPWindow({
                top: e.pageY,
                left: e.pageX,
                $pre: self
            }, function (body, prs) {
                if (!me["preViTip"]) { //                           
                    me["preViTip"] = $("<div><p class='_modifySection' style='cursor:pointer;'><i style='padding-right:4px;' class='fa fa-exchange'></i>" + eConfig.label.setSectionWidth + "</p>" +
                        "<p class='_resetSection' style='cursor:pointer;display:none;'><i style='padding-right:4px;' class='fa fa-resize-horizontal'></i>" + eConfig.label.resetSectionWidth + "</p>" +
                        "<p class='_delete_imag' style='cursor:pointer;'><i class='fa fa-cancel' style='padding-right:4px;'></i>" + eConfig.label.delete + "</p>" +
                        "<p class='_modifyedit' style='cursor:pointer;'><i class='fa fa-edit-1' style='padding-right:4px;'></i>" + eConfig.label.modify + "</p>" +
                        "<p class='_modifymove' style='cursor:pointer;'><i class='fa fa-move' style='padding-right:4px;'></i>" + eConfig.label.move + "</p></div>");
                    var $mody = me["preViTip"].children("p._modifyedit").click(function () {
                        var tip = $(this).parent();
                        tip.parent().parent().hide();
                        var pre = tip.data("$pre");
                        var $video = pre.children().children("video");
                        var params = {
                            height: $video.height(),
                            width: $video.width(),
                            margin: pre.css("margin"),
                            $pre: pre
                        };
                        me.openUploadVideoWindow("updateVideo", params);
                    });
                    if ($t.hasClass("k_video_url")) {//远程url视频
                        $mody.hide();
                    } else {
                        $mody.show();
                    }
                    me["preViTip"].children("p._modifySection").click(function () {
                        me.setSectionWidth();
                        me["preViTip"].detach();
                        me["tipWindow"].hide();
                    });
                    me["preViTip"].children("p._resetSection").click(function () {
                        me.resetSectionWidth();
                        me["preViTip"].detach();
                        me["tipWindow"].hide();
                    });
                    me["preViTip"].children("p._delete_imag").click(function () {
                        var tip = $(this).parent();
                        me.resizeBox.hide();
                        me.resizeBox.target = undefined;
                        if (me.movingAcn) {
                            me.movingAcn.hide();
                        }
                        tip.parent().parent().hide();
                        var pre = tip.data("$pre");
                        me._putUndoDataByNodeEl(pre);
                        var pel;
                        if (pre.hasClass("_section_div_")) {//兼容外部url视频
                            pel = pre;
                            pre.children().remove();
                        } else {
                            pel = pre.parent();
                            pre.remove();
                        }
                        tip.removeData("$pre");
                        if (pel.children().length === 0) {
                            me._getSpan().appendTo(pel);
                        }
                        me.moveToEnd(pel);
                        if (me.opts.onDeleted) {
                            me.opts.onDeleted.call(pre, pre.children("div").attr("src"));
                        }
                    });
                    me["preViTip"].children("p._modifymove").click(function () {
                        var tip = $(this).parent();
                        tip.parent().parent().hide();
                        var pre = tip.data("$pre");
                        var pEl;
                        if (pre.hasClass("_section_div_")) {//兼容外部url视频
                            pEl = pre;
                        } else {
                            pEl = pre.parent();
                            while (pEl.length > 0) {
                                if (pEl[0].tagName === "DIV") {
                                    break;
                                }
                                pEl = pEl.parent();
                            }
                        }
                        me._setMovingTargets([pEl], false);
                    });
                }
                var $_pre = prs["$pre"];
                if (me.startPElement.css("padding-left") !== "0px") {
                    me["preViTip"].children("p._resetSection").show();
                } else {
                    me["preViTip"].children("p._resetSection").hide();
                }
                me["preViTip"].data("$pre", $_pre);
                body.append(me["preViTip"]);
                if (pEl.parent().hasClass("k_editor_float_input")) {
                    me["preViTip"].children("p._modifymove").hide();
                } else {
                    me["preViTip"].children("p._modifymove").show();
                }
            });
            me._setMovingTargets([pEl], false, function () {
                me["tipWindow"].hide();
            });
            var $modifyIt = me["preViTip"].children("p._modifyedit");
            //大小拖动功能
            var box;
            if ($t.hasClass("k_video_url")) {//远程url视频
                box = $t.children("div");
                $modifyIt.hide();
            } else {
                box = self.children("div").children("video");
                $modifyIt.show();
            }
            me._createResizeBox(box);
        }
        return false;
    });
};
/***
 * 标题功能
 * ***/
Kedit.prototype.fontTitle = function (params, $btn) {
    console.log("fontTitle  >>>>" + JSON.stringify(params["font-title"]));
    var css = params["font-title"];
    this.foreachPTargets(function (p) {
        p.css({
            "line-height": css["line-height"]
        }).children("span").each(function () {
            $(this).css({
                "font-weight": css["font-weight"],
                "font-size": css["font-size"]
            });
        });
    });
};


/**向下折叠**/
Kedit.prototype.closedNext = function (params, $btn) {
    var sectionEl = this.getAnchorSectionEl();
    var countClosed = sectionEl.attr("closed_count");
    if (countClosed) {
        sectionEl.removeClass("_section_div_close_title").removeAttr("closed_count").removeAttr("closed_status");
        return;
    }
    var _this = this;
    this.openWindow({
        title: eConfig.label.closedCfg,
        width: 400,
        height: 200,
        contentFn: function (body, prs) {
            if (!_this["closedForm"]) {
                _this["closedForm"] = $(eConfig.closedForm);
                _this["closedForm"].find("#_section_c").on("change", function () {
                    var v = parseInt($(this).val());
                    var anchor = _this.getAnchorSectionEl();
                    var next = anchor.next("._section_div_");
                    while (next.length > 0 && next.hasClass("k_editor_closed_section")) {
                        next.removeClass("k_editor_closed_section").removeClass("_section_div_close_title");
                        next = next.next();
                    }
                    _this.closedSections = [];
                    var nextSection = anchor.next("._section_div_");
                    while (v > 0) {
                        if (nextSection.length > 0) {
                            _this.closedSections.push(nextSection);
                            nextSection.addClass("k_editor_closed_section");
                            nextSection = nextSection.next("._section_div_");
                        }
                        v--;
                    }
                });
                _this["closedForm"].find("button").click(function () {
                    var chk = _this["closedForm"].find("input[name='_status']:checked").val();
                    var pEl = _this.getAnchorSectionEl();
                    pEl.addClass("_section_div_close_title").attr("closed_count", _this.closedSections.length);
                    if (chk === "0") {
                        pEl.attr("closed_status", "true");
                    } else {
                        pEl.removeAttr("closed_status");
                    }
                    _this.closeWindow();
                });
            }
            var anchorPel = _this.getAnchorSectionEl();
            _this.closedSections = [];
            var $el = anchorPel.next().addClass("k_editor_closed_section"); //_section_div_close_title
            _this.closedSections.push($el);
            _this["closedForm"].find("#_section_c").val("1");
            body.append(_this["closedForm"]);
        }
    });
};
/**根据id删除table**/
Kedit.prototype._deleteTable = function (deleteTableId) {
    var _this = this;
    var arr = [];
    var deleteObj;
    for (var i = 0, len = _this.tables.length; i < len; ++i) {
        if (deleteTableId !== _this.tables[i].id) {
            arr.push(_this.tables[i]);
        } else {
            deleteObj = _this.tables[i];
        }
    }
    _this.tables = arr;
    if (deleteObj) {
        if (deleteObj === this.clickActivedObject) {
            this.clickActivedObject = undefined;
        }
        deleteObj.remove();
    }
};
/**清除选择的td记录**/
Kedit.prototype.clearSelectedTd = function () {
    this.cssTdArray = undefined;
};
/**
 * 表格修饰
 * ***/
Kedit.prototype.tableCss = function (method, params, button) {
    var cssTdArray = this.clickActivedObject.selectTdArray;
    var css2Td = method.indexOf("align") > -1;
    var collapsed = this._getDomRangeOnly().collapsed;
    if (collapsed) {
        css2Td = true;
    }
    if (css2Td && cssTdArray.length > 0) { //对齐修饰,修改修饰目标
        this._removePainTargets();
        var _this = this;
        var loopFn = function (ele) {
            _this.painTargets.push(ele);
            ele.children().each(function () {
                loopFn($(this));
            });
        };
        for (var i = 0, len = cssTdArray.length; i < len; ++i) {
            var td = cssTdArray[i];
            loopFn(td);
        }
        if (params["css"]) {
            this.css(params["css"]);
        } else {
            this[method](params, button);
        }
        return false;
    }
    return true;
};
/**保存**/
Kedit.prototype.save = function (params, button) {
    if (button.attr("disabled") || button.hasClass("disabled")) {
        return;
    }
    if (this.opts.onSave) {
        var res = this.getContent();
        this.opts.onSave.call(button, res, encodeURIComponent(res));
    }
};
/**格式刷**/
Kedit.prototype.paintBrush = function (prs, button) {
    var brushPel = this.startPElement;
    var seqData = this._getSectionSeqDatas(brushPel);
    if (seqData.isSeq) {
        this.brushSeqData = seqData;
    }
    var _this = this;
    $B.confirm({
        message: eConfig.label.brushmessage,
        width: 350,
        height: 120,
        title: eConfig.label.brushopts,
        okIcon: 'fa-ok-circled',
        noIcon: 'fa-minus-circled',
        okText: eConfig.label.yes,
        noText: eConfig.label.no,
        okFn: function () {
            _this.brushCss = _this._getRangeCss(true, true);
            _this.activedMenu = button.addClass("k_edit_btn_actived");
        },
        noFn: function () {
            _this.brushCss = _this._getRangeCss(true);
            _this.activedMenu = button.addClass("k_edit_btn_actived");
        }
    });
};
/**将样式刷到目标元素**/
Kedit.prototype.brush2Target = function () {
    this._clearRangeRecord();
    this.saveUserRange();
    this.setPaintTarget();
    var css, key, putUndo = false;
    var pCss = this.brushCss.pCss;//段落样式
    delete this.brushCss.pCss;
    if (pCss) {
        this.ignorePele = true;
        this.foreachPTargets(function (p) {
            p.css(pCss);
        });
    }
    var newCss = this.brushCss;
    if (!this.range.collapsed) {
        this._makeUndoDataByFocus();
        var cssKeys = Object.keys(this.brushCss);
        for (var i = 0, len = cssKeys.length; i < len; ++i) {
            css = {};
            key = cssKeys[i];
            css[key] = this.brushCss[key];
            if (css[key]) {
                this.css(css);
                putUndo = true;
            }
        }
    }
    this.activedMenu.removeClass("k_edit_btn_actived");
    this.brushCss = undefined;
    this.ignorePele = undefined;
    // 序列支持，只支持单个段落刷为相同序列
    if (this.brushSeqData) {
        if (this.startPElement[0] === this.endPElement[0]) {
            var linkSeqChain = [];
            var pEl = this.brushSeqData.seqEl.parent().next();
            var seqData = this.brushSeqData,
                tmpSeqData, nextSeqNum;
            var currentSeqIndex, nextSeqIndex;
            if (seqData.isChSeq) {
                currentSeqIndex = getChSeqIndex(seqData.seqNum);
            } else {
                currentSeqIndex = seqData.seqNum;
            }
            linkSeqChain.push(seqData.seqNum);
            while (pEl.length > 0) {
                tmpSeqData = this._getSectionSeqDatas(pEl);
                if (!tmpSeqData.isSeq) {
                    break;
                }
                if (this._isSameSeq(seqData.seqNumTxt, tmpSeqData.seqNumTxt, seqData.seqEl, tmpSeqData.seqEl)) {
                    //判断是否是相同连续序列
                    if (tmpSeqData.isChSeq) {
                        nextSeqIndex = getChSeqIndex(tmpSeqData.seqNum);
                    } else {
                        nextSeqIndex = tmpSeqData.seqNum;
                    }
                    if (currentSeqIndex !== nextSeqIndex - 1) {
                        break;
                    }
                    linkSeqChain.push(tmpSeqData.seqNum);
                    seqData = tmpSeqData;
                    pEl = pEl.next();
                    currentSeqIndex = nextSeqIndex;
                } else {
                    break;
                }
            }
            var seqSpan;
            var isNewSpan = false;
            var nextChSeqIndex;
            var existSeqData = this._getSectionSeqDatas(this.startPElement);
            var isUpdateSeq = true;
            if (existSeqData.isSeq) {
                for (var i1 = 0, len1 = linkSeqChain.length; i1 < len1; ++i1) {
                    if (linkSeqChain[i1] === existSeqData.seqNum) {//在一个连续的序列里面 不需要更新序列
                        isUpdateSeq = false;
                        break;
                    }
                }
                seqSpan = existSeqData.seqEl;
            } else {
                seqSpan = this._getSpan();
                isNewSpan = true;
            }
            if (isUpdateSeq) {
                if (seqData.isChSeq) {
                    nextSeqNum = getChNextSeq(seqData.seqNum);
                    seqSpan.html(seqData.seqNumTxt.replace(seqData.seqNum, nextSeqNum.seq));
                    nextChSeqIndex = nextSeqNum.index;
                } else {
                    nextSeqNum = seqData.seqNum + 1;
                    seqSpan.html(seqData.seqNumTxt.replace(/\d+/g, nextSeqNum));
                }
                if (isNewSpan) {
                    this.startPElement.prepend(seqSpan);
                }
                seqSpan.css(newCss);
                var cureSeqData = this._getSectionSeqDatas(this.startPElement);
                var nextEle = this.startPElement.next();
                var nextSeqData, chSeq;
                while (nextEle.length > 0) {
                    nextSeqData = this._getSectionSeqDatas(nextEle);
                    if (!nextSeqData.isSeq) {
                        break;
                    }
                    if (this._isSameSeq(cureSeqData.seqNumTxt, nextSeqData.seqNumTxt, cureSeqData.seqEl, nextSeqData.seqEl)) {
                        if (nextSeqData.isChSeq) {
                            nextChSeqIndex++;
                            chSeq = chSeqArray[nextChSeqIndex];
                            nextSeqData.seqEl.html(nextSeqData.seqNumTxt.replace(nextSeqData.seqNum, chSeq));
                        } else {
                            nextSeqNum++;
                            nextSeqData.seqEl.html(nextSeqData.seqNumTxt.replace(/\d+/g, nextSeqNum));
                        }
                    } else {
                        break;
                    }
                    nextEle = nextEle.next();
                }
            }
        }
    }
    this.brushSeqData = undefined;
    if (putUndo) {
        this._putUndo();
    }
    this["undoRedoRec"] = undefined;
};

/***
 * 清空
 * * */
Kedit.prototype.clear = function () {
    this._hideOthersIcon();
    for (var i = 0, len = this.tables.length; i < len; ++i) {
        if (this.tables[i].remove) {
            this.tables[i].remove();
        }
    }
    this.$inputWrap.children(".k_edit_float_panel").remove();
    this.tables = [];
    var firstP = this.$input.children("div").first();
    var id = getUUID();
    firstP.html('<span style="' + eConfig.defaultStyle + '" id="' + id + '">\u200B</span>');
    firstP.nextAll().remove();
    firstP.removeAttr("contenteditable");
    this.moveToEnd(firstP);
    firstP.css(eConfig.pElementCss);
    _getBody().children("#k_edit_table_anchor").hide();
    if (this.sectionResizeBar) {
        this.sectionResizeBar.remove();
    }
    if (this.sectionResizeBar2) {
        this.sectionResizeBar2.remove();
    }
    if (this.movingAcn) {
        this.movingAcn.hide();
    }
};
/**源码/视图**/
Kedit.prototype.source = function (prs, button) {
    var sections = this.$input.children("div");
    if (!this["sourceView"]) {
        this["sourceView"] = $('<textarea class="k_box_size" style="display:none; width:100%;height:98%;resize: none; border: 0px; padding: 0px; margin: 0px; overflow-y: auto; outline: 0px;" />');
    }
    var display = this["sourceView"].css("display");
    if (display === "none") {
        button.addClass("k_edit_btn_actived");
        var contents = [];
        sections.each(function () {
            var $s = $(this);
            contents.push($s[0].outerHTML);
            contents.push("\n");
        });
        this.$inputWrap.children(".k_edit_float_panel").each(function () {
            contents.push($(this)[0].outerHTML);
            contents.push("\n");
        });
        this["sourceView"].val(contents.join("")).show();
        this.$input.hide();
        this["sourceView"].insertAfter(this.$input);
        this.clearUserRange(true);
        this.$inputWrap.children(".k_edit_float_panel").hide();
        if (this.floatTools) {
            this.floatTools.hide();
        }
        if (this.floatPropPanel) {
            this.floatPropPanel.hide();
        }
        this.closeAllWindow();
    } else {
        button.removeClass("k_edit_btn_actived");
        this["sourceView"] = this["sourceView"].remove().hide().val('');
        this.$input.show();
        this.$inputWrap.children(".k_edit_float_panel").show();
        this.moveToEnd(this.$input.children().last());
    }
};
/**字体间距 letter-spacing**/
Kedit.prototype.fontSpace = function (params) {
    var cmd = params.cmd;
    var user2 = params.user2;
    //console.log("user2 = "+user2);
    var fn = function ($i, i) {
        if (cmd === "reset") {
            $i.css("letter-spacing", "0px");
        } else {
            var l = $i.css("letter-spacing");
            if (!l) {
                l = "0px";
            } else {
                l = parseInt(l.replace("px", ""));
            }
            if (cmd === "accretion") {
                $i.css("letter-spacing", ++l);
            } else if (cmd === "reduce") {
                $i.css("letter-spacing", --l);
            }
        }
    };
    if (user2 === "1") {
        this.foreachTargets(fn);
    } else {
        this.foreachPTargets(fn);
    }
};
/***插入表格***/
Kedit.prototype.insertTable = function (params) {
    var col = params["col"];
    var row = params["row"];
    var range = this.range;
    if (!range) {
        return;
    }
    var container = this.endPElement;
    if (!container) {
        var ancContainer = range.commonAncestorContainer;
        if (ancContainer.nodeType === 3) {
            ancContainer = ancContainer.parentNode;
        }
        container = $(ancContainer);
        if (container[0].tagName !== sectionTag) {
            container = container.parent();
            while (container[0].tagName !== sectionTag) {
                container = container.parent();
            }
        }
    }
    //var childs = container.children();
    var txt = container.text();
    var isEmpty = txt === "" || txt === "\u200B";
    if (!isEmpty) {
        container = this.insertPElement(container);
    }
    container.html("");
    var table = new Table(this).init(col, row);
    table.jqObj.attr("id", getUUID());
    this.tables.push(table);
    table.appendTo(container);
    container.children("br").remove();
    var firstTd = table.tbody.children().first().children().first();
    var _this = this;
    if (container.next().length === 0) {
        var $p = this.createPElement();
        $p.insertAfter(container);
    }
    this.createCrossRange(firstTd, firstTd);
};

/**加粗**/
Kedit.prototype.bold = function (params) {
    var curValue = this.getCurrentCssValue("font-weight");
    if (curValue === "400" || !curValue) {
        this.css({
            "font-weight": "bold"
        });
    } else {
        this.css({
            "font-weight": "normal"
        });
    }
};
/**斜体**/
Kedit.prototype.italic = function (params) {
    var curValue = this.getCurrentCssValue("font-style");
    if (curValue && curValue === "normal") {
        this.css({
            "font-style": "italic"
        });
    } else {
        this.css({
            "font-style": "normal"
        });
    }
};
/**
 * 下划线
 * **/
Kedit.prototype.underline = function (params) {
    var curValue = this.getCurrentCssValue("text-decoration");
    var _this = this;
    if (curValue && curValue.indexOf("none") < 0 && curValue.indexOf("line-through") < 0) {
        this.css(function (jqObj) {
            _this.cssing = {
                "text-decoration": "none"
            };
            jqObj.css(_this.cssing);
            var $p = jqObj.parent();
            if ($p[0].tagName !== "DIV") {
                var css = _this._getCopyStyle($p);
                delete css["text-decoration"];
                $p.removeAttr("style").css(css);
            }
        });
    } else {
        this.css(function (jqObj) {
            _this.cssing = {
                "text-decoration": "underline"
            };
            jqObj.css(_this.cssing);
        });
    }
};
/***
 * 删除线
 * ***/
Kedit.prototype.strikethrough = function (params) {
    var curValue = this.getCurrentCssValue("text-decoration");
    if (curValue && curValue.indexOf("none") < 0 && curValue.indexOf("underline") < 0) {
        this.css({
            "text-decoration": "none"
        });
    } else {
        this.css({
            "text-decoration": "line-through"
        });
    }
};
/**上标 * **/
Kedit.prototype.superscript = function (params) {
    var _this = this;
    this.foreachTargets(function ($t, i) {
        var verticalAlign = $t.css("vertical-align");
        if (verticalAlign && verticalAlign === "super") {
            var css = _this._getCopyStyle($t.parent());
            var fontSize = css["font-size"];
            var newCss = _this._getCopyStyle($t);
            newCss["font-size"] = fontSize;
            delete newCss["vertical-align"];
            $t.removeAttr("style");
            $t.css(newCss);
        } else {
            $t.css({
                "vertical-align": "super",
                "font-size": "smaller"
            });
        }
    });
};
/**下标**/
Kedit.prototype.subscript = function (params) {
    var _this = this;
    this.foreachTargets(function ($t, i) {
        var verticalAlign = $t.css("vertical-align");
        if (verticalAlign && verticalAlign === "sub") {
            var css = _this._getCopyStyle($t.parent());
            var fontSize = css["font-size"];
            var newCss = _this._getCopyStyle($t);
            newCss["font-size"] = fontSize;
            delete newCss["vertical-align"];
            $t.removeAttr("style");
            $t.css(newCss);
        } else {
            $t.css({
                "vertical-align": "sub",
                "font-size": "smaller"
            });
        }
    });
};
/**字体**/
Kedit.prototype.fontFamily = function (params) {
    var fontFamily = params["font-family"];
    this.css({
        "font-family": fontFamily
    });
};
/**字体颜色**/
Kedit.prototype.fontColor = function (params) {
    this.css({
        color: params.color
    });
    this.changeSelectionColor("color", params.color);
};
/**背景色**/
Kedit.prototype.backgroundColor = function (params) {
    this.css({
        "background-color": params.color
    });
    var range = this.getDomRange();
    var collapsed = range.collapsed;
    if (collapsed) {
        var ancContainer = range.commonAncestorContainer;
        if (ancContainer.nodeType === 3) {
            ancContainer = ancContainer.parentNode;
        }
        ancContainer = $(ancContainer);
        var td;
        while (ancContainer.length > 0) {
            if (ancContainer.hasClass("_section_div_")) {
                break;
            }
            if (ancContainer[0].tagName === "TD") {
                td = ancContainer;
                break;
            }
            ancContainer = ancContainer.parent();
        }
        if (td) {
            td.css("background-color", params.color);
        }
    }
    this.changeSelectionColor("background-color", params.color);
};
/**清除格式支持只清除选区部分
 * 需要支持浮动面板的清除 eraserTip eraserAll eraserSelected eraserSection
 * **/
Kedit.prototype.eraser = function (params) {
    var range = this.getDomRange();
    var clearSpan = function (jqEle) {
        var tagName = jqEle[0].tagName;
        if (tagName === "SPAN") {
            jqEle.removeAttr("style");
            jqEle.attr("style", eConfig.defaultStyle);
            jqEle.children().each(function () {
                clearSpan($(this));
            });
        } else if (tagName === "TD") {
            jqEle.css({
                "border-width": "1px",
                "border-style": "dashed",
                "border-color": "rgb(175, 201, 222)",
                "background-color": "none"
            });
        }
    };
    var _this = this;
    this.confirmWin = $B.confirm({
        title: eConfig.label.eraserTip,
        message: eConfig.label.eraserTip,
        createToolsFn: function () {
            var wrap = this;
            var tool = $("<div class='k_confirm_buttons_wrap'></div>").appendTo(wrap);
            $("<button style='width:33.33333%' class='yes'><i  class='fa fa-eraser'>\u200B</i>" + eConfig.label.eraserAll + "</button>").appendTo(tool).click(function () {
                _this.confirmWin.close(true);
                var newFrag = document.createDocumentFragment();
                newFrag.appendChild(document.createElement("div"));
                var wrap = newFrag.firstChild;
                var html = _this.$input.html();
                _this.$input.children().remove();
                wrap.innerHTML = html;
                var htmlContent = [];
                var $wrap = $(wrap);
                $wrap.children().each(function () {
                    var $p = $(this).attr("style", "line-height: 21px; font-size: 14px;");
                    $p.children().each(function () {
                        clearSpan($(this));
                    });
                    htmlContent.push($p[0].outerHTML);
                });              
                //浮动文本 、图片
                _this.$inputWrap.children(".k_edit_float_panel").each(function () {
                    var tmp = $(this);
                    var $tag = tmp.clone();
                    var input = $tag.children(".k_editor_float_input").removeAttr("contenteditable");
                    input.children("div").each(function () {
                        var $p = $(this).attr("style", "line-height: 21px; font-size: 14px;");
                        $p.children().each(function () {
                            clearSpan($(this));
                        });
                    });
                    htmlContent.push($tag[0].outerHTML);
                    tmp.remove();
                });
                _this.setContent(htmlContent.join(""));
            });
            $("<button  style='width:33.33333%' class='no'><i  class='fa fa-eraser'>\u200B</i>" + eConfig.label.eraserSelected + "</button>").appendTo(tool).click(function () {
                _this.confirmWin.close(true);
                _this.setPaintTarget();
                _this.css(function (jqObj) {
                    clearSpan(jqObj);
                });
            });
            $("<button  style='width:33.33333%' class='yes'><i  class='fa fa-eraser'>\u200B</i>" + eConfig.label.eraserSection + "</button>").appendTo(tool).click(function () {
                _this.confirmWin.close(true);
                var startEl = _this.startPElement;
                var eachFn = function(){
                    clearSpan($(this));      
                };
                while(startEl.length > 0){//单个段落  
                    startEl.removeAttr("style").css(eConfig.pElementCss); 
                    startEl.children().each(eachFn);                            
                    if( startEl[0] === _this.endPElement[0]){
                        break;
                    }
                    startEl = startEl.next();
                }
            });
        }
    });
};
/**创建列表**/
Kedit.prototype._makeList = function (isOl, listStyle) {
    var insert = true;
    var listRootNode; // 列表根ol\ul对象
    if (this.range) {
        var listHtml;
        var container = this.range.commonAncestorContainer;
        var rangeInfo = this._getRangeInfo();
        var li, i, len, next;
        var isCrossPelement = this.isCrossPElement();
        if (!isCrossPelement) { //
            if (container.nodeType === 3) {
                container = $(container.parentNode);
            } else {
                container = $(container);
            }
            while (container.length > 0) {
                if (container.hasClass("_section_div_")) {
                    break;
                }
                var tagName = container[0].tagName;
                if (tagName === "TABLE" || tagName === "LI" || tagName === "OL" || tagName === "UL") {
                    insert = false;
                    if (tagName === "LI") {
                        listRootNode = container.parent();
                    } else if (tagName === "OL" || tagName === "UL") {
                        listRootNode = container;
                    }
                    break;
                }
                container = container.parent();
            }
            var lType = "";
            if(listStyle === "1"){
                lType = "decimal";
            }else if(listStyle === "i"){
                lType = "lower-roman";
            }else if(listStyle === "a"){
                lType = "lower-latin";
            }
            if (insert && listStyle !== "none") {                
                var html = container.html();
                container.children().remove();
                if (isOl) {
                    listHtml = "<ol type='" + listStyle + "' style='list-style-type:" + lType + ";list-style-position:inside;padding:0;margin:0;margin-block-start:0;padding-inline-start:0;-webkit-padding-start:0px;-webkit-margin-before:0;-webkit-margin-after:0;'><li id='" + getUUID() + "'>" + html + "</li></ol>";
                } else {
                    listHtml = "<ul style='list-style-position:inside;padding:0;margin:0;list-style-type:" + listStyle + ";padding-inline-start:0;-webkit-padding-start:0px;-webkit-margin-before:0;-webkit-margin-after:0;'><li id='" + getUUID() + "'>" + html + "</li></ul>";
                }
                container.append(listHtml);
                next = container.next();
                if (next.length === 0) {
                    this.insertPElement();
                    if (isOl) {
                        li = container.children("ol").children("li").last();
                    } else {
                        li = container.children("ul").children("li").last();
                    }
                }
                this.rebuildUserRange(rangeInfo);
            } else if (listRootNode) {
                var lastLi;
                if (isOl) { //有序列表
                    if (listStyle === "none") {
                        this._li2p(listRootNode);
                    } else {
                        listRootNode.attr("type", listStyle);
                        listRootNode.css("list-style-type", lType);
                        lastLi = listRootNode.children().last();
                    }
                } else { //符号列表
                    if (listStyle === "none") {
                        this._li2p(listRootNode);
                    } else {
                        listRootNode.css("list-style-type", listStyle);
                        lastLi = listRootNode.children().last();
                    }
                }
                this.rebuildUserRange(rangeInfo);
            }
        } else { //选择了多个段落
            var nodeName = container.nodeName;
            if (nodeName === "OL") {
                return;
            }
            if (nodeName === "UL") {
                $(container).children().each(function () {
                    $(this).css("list-style-type", listStyle);
                });
                return;
            }
            var htmlArray = [],
                lineHeightArray = [],
                id,
                firstPele,
                removeEles = []; //移除的p元素
            if (this.painTargets.length === 0) {
                this.setStartAndEndPElementByRange();
            }
            //按段落形成有序内容              
            this.foreachPTargets(function (p) {
                if (!firstPele) {
                    firstPele = p;
                } else {
                    removeEles.push(p);
                }
                htmlArray.push(p.html());
                lineHeightArray.push(p.css("line-height"));
                var firstChild = p.children().first();
                var tagName = firstChild[0].tagName;
                if (tagName === "TABLE" || tagName === "LI") {
                    htmlArray = [];
                    firstPele = undefined;
                    removeEles = undefined;
                    return false;
                }
            });
            if (firstPele) {
                var eleIdsArray = [];
                for (i = 0, len = removeEles.length; i < len; ++i) {
                    id = removeEles[i].attr("id");
                    removeEles[i].remove();
                    eleIdsArray.push(id);
                }
                firstPele.html('');
                if (isOl) {
                    listHtml = "<ol type='" + listStyle + "' style='list-style-type:" + lType + ";list-style-type:decimal;list-style-position:inside;padding:0;margin:0;padding-inline-start:0;-webkit-padding-start:0px;-webkit-margin-before:0;-webkit-margin-after:0;'></ol>";
                } else {
                    listHtml = "<ul style='list-style-position:inside;padding:0;margin:0;list-style-type:" + listStyle + ";padding-inline-start:0;-webkit-padding-start:0px;-webkit-margin-before:0;-webkit-margin-after:0;'></ul>";
                }
                var ol = $(listHtml).appendTo(firstPele);
                for (i = 0, len = htmlArray.length; i < len; ++i) {
                    if (i === 0) {
                        id = getUUID();
                    } else {
                        id = eleIdsArray[i - 1];
                    }
                    ol.append("<li style='line-height:" + lineHeightArray[i] + "' id='" + id + "'>" + htmlArray[i] + "</li>");
                }
                next = firstPele.next();
                if (next.length === 0) {
                    this.insertPElement();
                    if (isOl) {
                        li = firstPele.children("ol").children("li").last();
                    } else {
                        li = firstPele.children("ul").children("li").last();
                    }
                }
                this.rebuildUserRange(rangeInfo);
            }
        }
    }
};
/**li转p段落**/
Kedit.prototype._li2p = function (listRootNode) {
    var p = listRootNode.parent();
    var firstPContent,
        newpContent = [],
        newpIdArray = [];
    //var fisrtLiId ;
    listRootNode.children().each(function (i) {
        var li = $(this);
        if (i === 0) {
            firstPContent = li.html();
            //fisrtLiId = li.attr("id");
        } else {
            newpContent.push(li.html());
            newpIdArray.push(li.attr("id"));
        }
    });
    p.html(firstPContent);//.attr("id" , fisrtLiId)
    for (var i = 0, len = newpIdArray.length; i < len; ++i) {
        var _c = newpContent[i];
        var $p = $("<" + sectionTag + " id='" + newpIdArray[i] + "' class='_section_div_'>" + _c + "</" + sectionTag + ">");
        p = $p.insertAfter(p);
    }
    listRootNode.remove();
    this.moveToEnd(p);
};
/***有序列表***/
Kedit.prototype.orderList = function (params) {
    var listStyle = params["list-style-type"];
    this._makeList(true, listStyle);
    this.createTargetsByRange();//重新建立 选区数据
};
/**插入代码**/
Kedit.prototype.insertCode = function (params) {
    var code = params.code;
    var insertTag = this._getInsertP();
    var pre = $("<pre style='line-height:1.6em;background-color:#F5F5F5;border-radius: 3px;padding: 3px 5px;margin: 0 3px;font-weight:normal;font-size:14px;color:#666666;'></pre>");
    pre.html(code);
    var span = insertTag.children("span").first();
    this.moveToEnd(span);
    span.siblings().remove();
    span.html("");
    pre.appendTo(span);
    this._bindPreEvents(pre);
    var $next = insertTag.next();
    if ($next.length === 0) {
        $next = this.createPElement();
        $next.insertAfter(insertTag);
        this.moveToEnd($next);
    }
};
Kedit.prototype._bindPreEvents = function ($pre) {
    $pre.mouseup(function (e) {
        var self = $(this);
        var pEl = self.parent();
        while (pEl.length > 0) {
            if (pEl[0].tagName === "DIV") {
                break;
            }
            pEl = pEl.parent();
        }
        var me = self.data("edit");
        me.startPElement = pEl;
        me.endPElement = pEl;
        _getBody().trigger("mouseup");
        me.openTIPWindow({
            top: e.pageY,
            left: e.pageX,
            $pre: self
        }, function (body, prs) {
            if (!me["preTip"]) { //                           
                me["preTip"] = $("<div><p class='_resetSection' style='cursor:pointer;display:none;'><i style='padding-right:4px;' class='fa fa-resize-horizontal'></i>" + eConfig.label.resetSectionWidth + "</p>" +
                    "<p class='_modifySection' style='cursor:pointer;'><i style='padding-right:4px;' class='fa fa-exchange'></i>" + eConfig.label.setSectionWidth + "</p>" +
                    "<p class='_delete_imag' style='cursor:pointer;'><i class='fa fa-cancel' style='padding-right:4px;'></i>" + eConfig.label.deleteCode + "</p>" +
                    "<p class='_modifyCode' style='cursor:pointer;'><i class='fa fa-edit' style='padding-right:4px;'></i>" + eConfig.label.modifyCode + "</p>" +
                    "<p class='_modifymove' style='cursor:pointer;'><i class='fa fa-move' style='padding-right:4px;'></i>" + eConfig.label.move + "</p></div>");
                me["preTip"].children("p._modifySection").click(function () {
                    me.setSectionWidth();
                    me["preTip"].detach();
                    me["tipWindow"].hide();
                });
                me["preTip"].children("p._resetSection").click(function () {
                    me.resetSectionWidth();
                    me["preTip"].detach();
                    me["tipWindow"].hide();
                });
                me["preTip"].children("p._delete_imag").click(function () {
                    var tip = $(this).parent();
                    tip.parent().parent().hide();
                    var pre = tip.data("$pre");
                    var span = pre.parent();
                    //删除操作 做记录                        
                    me._putUndoDataByNodeEl(span);
                    pre.remove();
                    tip.removeData("$pre");
                    var txt = span.text();
                    if (txt === "" && txt !== "\u200B") {
                        span.text("\u200B");
                    }
                    me.moveToEnd(span);
                });
                me["preTip"].children("p._modifyCode").click(function () {
                    var tip = $(this).parent();
                    tip.parent().parent().hide();
                    var pre = tip.data("$pre");
                    tip.removeData("$pre");
                    me.openCodeWindow("insertCode", { undo: false, needRange: false, sourceTag: pre });
                });
                me["preTip"].children("p._modifymove").click(function () {
                    var tip = $(this).parent();
                    tip.parent().parent().hide();
                    var pre = tip.data("$pre");
                    var pEl = pre.parent();
                    while (pEl.length > 0) {
                        if (pEl[0].tagName === "DIV") {
                            break;
                        }
                        pEl = pEl.parent();
                    }
                    me._setMovingTargets([pEl], false);
                    //console.log("移动代码>>>>>>>>>>>>>>>>>>>>");
                });
            }
            var $_pre = prs["$pre"];
            if (me.startPElement.css("padding-left") !== "0px") {
                me["preTip"].children("p._resetSection").show();
            } else {
                me["preTip"].children("p._resetSection").hide();
            }
            me["preTip"].data("$pre", $_pre);
            body.append(me["preTip"]);
            if (pEl.parent().hasClass("k_editor_float_input")) {
                me["preTip"].children("p._modifymove").hide();
            } else {
                me["preTip"].children("p._modifymove").show();
            }
        });
        //console.log("mouse up  code pre >>>>>>>>>>>>>>>>>>>");                
        me._setMovingTargets([pEl], false, function () {
            me["tipWindow"].hide();
        });
        return false;
    }).mousedown(function () {
        var self = $(this);
        var me = self.data("edit");
        me._closeCxtMenuImd();
        stopDefaultctxMenu();
        return false;
    }).keydown(function () {
        return false;
    }).keyup(function () {
        return false;
    }).data("edit", this);
};
/**无序列表**/
Kedit.prototype.unorderList = function (params) {
    var listStyle = params["list-style-type"];
    this._makeList(false, listStyle);
    this.createTargetsByRange();//重新建立 选区数据
};
/**字体大小**/
Kedit.prototype.fontSize = function (params) {
    var css = {
        "font-size": params["font-size"]
    };
    this.css(css);
};
/**居中对齐**/
Kedit.prototype.alignCenter = function (params) {
    this.setStartAndEndPElementByRange();
    var _this = this;
    this.foreachPTargets(function (p) {
        p.css({
            "text-align": "center"
        });
    });
};
Kedit.prototype.alignLeft = function (params) {
    this.setStartAndEndPElementByRange();
    this.foreachPTargets(function (p) {
        p.css({
            "text-align": "left"
        });
    });
};
Kedit.prototype.alignRight = function (params) {
    this.setStartAndEndPElementByRange();
    this.foreachPTargets(function (p) {
        p.css({
            "text-align": "right"
        });
    });
};
/**取消链接**/
Kedit.prototype.unlink = function (params) {
    var range = this.range;
    var ancer = range.commonAncestorContainer;
    var aEle;
    if (ancer.nodeType === 3) {
        aEle = $(ancer.parentNode);
    } else {
        aEle = $(aEle);
    }
    if (aEle[0].nodeName === "A") {
        var html = aEle.text();
        var cpStyle = this._getCopyStyle(aEle);
        var parent = aEle.parent();
        aEle.remove();
        parent.html(html).css(cpStyle);
        //parent.removeAttr("contenteditable");
        this.createCrossRange(parent, parent);
    }
};
/**编辑链接**/
Kedit.prototype.editLink = function (params) {
    var range = this.range;
    var ancer = range.commonAncestorContainer;
    var aEle;
    if (ancer.nodeType === 3) {
        aEle = $(ancer.parentNode);
    } else {
        aEle = $(aEle);
    }
    if (aEle[0].nodeName === "A") {
        this.createCrossRange(aEle, aEle);
        this._openLinkWindow({
            wrap: aEle
        }, aEle.text());
    }
};
/**打开链接设置窗口
 * params = {nodeValue:,startOffset:,endOffset:,wrap}
 * **/
Kedit.prototype._openLinkWindow = function (params, txt) {
    var _this = this;
    this.openWindow({
        title: eConfig.label.updateLink,
        width: 400,
        height: 200,
        contentFn: function (body, params) {
            var $addr, $target;
            if (!_this["linkForm"]) {
                _this["linkForm"] = $(eConfig.linkForm);
                var validObj,
                    $name = _this["linkForm"].find("#_link_name");
                $addr = _this["linkForm"].find("#_addr_url"),
                    $target = _this["linkForm"].find("#_target_");
                _this["linkForm"].find("button").click(function () {
                    if (!validObj || validObj.valid()) {
                        _this.closeWindow();
                        var prs = _this["linkForm"].data("params");
                        _this["linkForm"].removeData("params");
                        var t = $target.prop("checked") ? '_blank' : '_self';
                        var addr = $addr.val();
                        if (addr.indexOf("http") < 0) {
                            addr = "http://" + addr;
                        }
                        if (prs.wrap[0].nodeName === "A") {
                            prs.wrap.attr({
                                target: t,
                                href: addr
                            }).text($name.val());
                        } else {
                            var a = '<a target="' + t + '" href="' + addr + '" id="' + getUUID() + '">';
                            var $a;
                            if (prs.mutilTags) {
                                console.log("跨元素选区》》》》》");
                                var aList = prs.wrap;
                                var aEle, firstEl, lastEl;
                                for (var i = 0, len = aList.length; i < len; ++i) {
                                    aEle = aList[i];
                                    aEle.html(a + aEle.text() + "</a>");
                                    $a = aEle.children();
                                    if (i === 0) {
                                        firstEl = $a;
                                    }
                                    if (i === len - 1) {
                                        lastEl = $a;
                                    }
                                    _this._bindAEleEvents($a);
                                }
                                _this.createCrossRange(firstEl, lastEl);
                            } else {
                                a = a + $name.val() + '</a>';
                                var spanHtmls = _this._text2spanWrap(prs.nodeValue, prs.startOffset, prs.endOffset, true);
                                var copyStyle = _this._getCopyStyle(prs.wrap);
                                if (spanHtmls !== "") {
                                    var spans = $(spanHtmls).insertAfter(prs.wrap);
                                    prs.wrap.remove();
                                    var taget;
                                    spans.each(function () {
                                        var $t = $(this);
                                        if ($t.hasClass("_wrap_target_node_")) {
                                            taget = $t;
                                            return false;
                                        }
                                    }).css(copyStyle);
                                    taget.html(a).removeClass("_wrap_target_node_");
                                    $a = taget.children();
                                } else {
                                    prs.wrap.html(a);
                                    $a = prs.wrap.children();
                                }
                                $a.css("text-decoration", "underline");
                                _this._getSpan().insertAfter($a.parent());
                                _this.createCrossRange($a, $a);
                                $a.css(copyStyle);
                                _this._bindAEleEvents($a);
                            }
                        }
                    }
                });
                //创建验证
                if ($B.Validate) {
                    validObj = new $B.Validate({
                        "_link_name": [{
                            rule: 'require'
                        }],
                        "_addr_url": [{
                            rule: 'require'
                        }, {
                            rule: 'url'
                        }]
                    }, _this["linkForm"]);
                }
            }
            _this["linkForm"].data("params", params);
            _this["linkForm"].find("#_link_name").val(txt);
            if (params.wrap[0].nodeName === "A") {
                $addr = _this["linkForm"].find("#_addr_url");
                $target = _this["linkForm"].find("#_target_");
                $addr.val(params.wrap.attr("href"));
                if (params.wrap.attr("target") === "_blank") {
                    $target.prop("checked", true);
                } else {
                    $target.prop("checked", false);
                }
            }
            body.append(_this["linkForm"]);
        }
    }, params);
};
/**
 * 插入超链接
 * ***/
Kedit.prototype.link = function (params) {
    var range = this.range;
    var tmpArray = [];
    var i, len;
    var ancer = range.commonAncestorContainer;
    var prs = {
        nodeValue: undefined,
        startOffset: range.startOffset,
        endOffset: range.endOffset,
        wrap: undefined
    };
    if (ancer.nodeType !== 3) {
        this.setPaintTarget();
        var tgs = this.painTargets;
        var tg;
        for (i = 0, len = tgs.length; i < len; ++i) {
            tg = tgs[i];
            tmpArray.push(tg.text());
        }
        prs.nodeValue = tmpArray.join("");
        prs.wrap = tgs;
        prs.mutilTags = true;//跨标签设置超链接
        //console.log(eConfig.label.nosuport + tmpArray.join(""));
        //return;
    } else {
        var parent = $(ancer.parentNode);
        prs.nodeValue = ancer.nodeValue;
        prs.wrap = parent;
        for (i = 0, len = prs.nodeValue.length; i < len; ++i) {
            if (i >= prs.startOffset && i < prs.endOffset) {
                tmpArray.push(prs.nodeValue[i]);
            } else if (i >= prs.endOffset) {
                break;
            }
        }
    }
    var txt = tmpArray.join("");
    this._openLinkWindow(prs, txt);
};
/**绑定a标签事件**/
Kedit.prototype._bindAEleEvents = function ($a) {
    $a.mouseup(function (e) {
        var aEle = $(this);
        var me = aEle.data("selft");
        var addr = aEle.attr("href");
        var lastEl, firstEl, $el;
        var txtArray = [];
        var $aArray = [];
        var span = aEle.parent();
        var prev = span.prev();
        while (prev.length > 0) {
            $el = prev.children("a");
            if ($el.length === 0) {
                break;
            }
            if (addr !== $el.attr("href")) {
                break;
            }
            txtArray.unshift($el.text());
            $aArray.unshift($el);
            prev = prev.prev();
        }
        txtArray.push(aEle.text());
        $aArray.push(aEle);

        var next = span.next();
        while (next.length > 0) {
            $el = next.children("a");
            if ($el.length === 0) {
                break;
            }
            if (addr !== $el.attr("href")) {
                break;
            }
            txtArray.push($el.text());
            $aArray.push($el);
            next = next.next();
        }
        //var flag = aEle.attr("flag");

        me["_clickLinkTag"] = $aArray;
        firstEl = $aArray[0];
        lastEl = $aArray[$aArray.length - 1];

        var txt = txtArray.join("");
        me.openTIPWindow({
            top: e.pageY,
            left: e.pageX
        }, function (body) {
            if (!me["linkTip"]) {
                me["linkTip"] = $("<div>" + eConfig.label.visit + "：<a target='blank' href='" + addr + "'>" + txt + "</a><br/><p style='cursor:pointer;'>" + eConfig.label.deleteLink + "</p></div>");
                me["linkTip"].children("p").click(function () {
                    var $t = $(this);
                    var eles = me._clickLinkTag;
                    if (eles.length > 0) {//加入撤销记录
                        me._putUndoDataByNodeEl(eles[0]);
                    }
                    var ele, parent;
                    for (var j = 0, jlen = eles.length; j < jlen; ++j) {
                        ele = eles[j];
                        parent = ele.parent();
                        if (parent.contents().length === 1) {
                            parent.html("\u200B");
                        }
                        ele.remove();
                    }
                    me._clickLinkTag = undefined;
                    me.moveToEnd(parent);
                    $t.parent().parent().parent().hide();
                    if (me.opts.onDeleted) {
                        me.opts.onDeleted.call(ele, ele.attr("href"));
                    }
                });
            }
            me["linkTip"].children("a").attr("href", addr).text(txt);
            body.append(me["linkTip"]);
        });
        me.createCrossRange(firstEl, lastEl);
    }).data("selft", this);
};
/**
 * 插入表情
 * **/
Kedit.prototype.emotion = function (prs) {
    var insertSpan = this._getInsertSpan();
    if (insertSpan) {
        var base64, height, width;
        if (prs.isIcon) {
            base64 = prs.icon;
            height = prs.height;
            width = prs.width;
        } else {
            height = 19;
            width = 19;
            base64 = window.kemConfig[prs.gif];
        }
        var gif = $("<span style='" + eConfig.defaultStyle + "' id='" + getUUID() + "'>\u200B<img  class='_emotion_' id='" + getUUID() + "' src='" + base64 + "' style='width:" + width + "px;height:" + height + "px;margin-left:1px ;margin-right:1px;'/>\u200B</span>");
        gif.css("background", "none");
        gif.insertAfter(insertSpan);
        var span = this._getSpan().insertAfter(gif);
        var prevSpan = gif.prev();
        var copyStyle;
        if (prevSpan.length > 0) {
            copyStyle = this._getCopyStyle(prevSpan);
            span.css(copyStyle);
        } else {
            copyStyle = span.parent().css("background-color");
            span.css("background-color", copyStyle);
        }
        this._bindImageEvents(gif.children("img"));
        this.moveToEnd(span);
    }
};
/**插入图片
 * {"undo":false,"needRange":false,"url":"20180712095010.png","width":"100","height":"100","position":"center"}**/
Kedit.prototype.picture = function (params) {
    var url = params.url,
        width = params.width,
        height = params.height,
        position = params.position;
    var _this = this;
    var margin = {
        "margin-top": params.top + "px",
        "margin-right": params.right + "px",
        "margin-bottom": params.bottom + "px",
        "margin-left": params.left + "px"
    };
    if (this.clickActivedObject && this.clickActivedObject.className === "table") {
        var clickTd = this.clickActivedObject.clickTd;
        if (!clickTd && this.range) {
            var acontainer = this.range.commonAncestorContainer;
            if (acontainer.nodeType === 3) {
                acontainer = $(acontainer.parentNode);
            } else {
                acontainer = $(acontainer);
            }
            while (acontainer.length > 0) {
                if (acontainer[0].tagName === "TD") {
                    clickTd = acontainer;
                    break;
                }
                acontainer = acontainer.parent();
            }
        }
        if (clickTd) {
            var $img = this._createImage(url, width, height).css(margin);            
            if (position !== 'inner') {
                $img.prependTo(clickTd);
                clickTd.css("text-align", position);
                if(params.isAuto){
                    $img.width("100%");
                    $img.height("auto");
                }
                if(params.link){
                    if(params.link === ""){
                        $img.removeAttr("link");
                    }else{
                        $img.attr("link",params.link);
                    }        
                }
            } else {//行内插入
                this.lineInnerImage(url, width, height, true);
            }
            this.clickActivedObject.reSize();
            this.clickActivedObject.reSize(true);//设置大小 
        }
        return;
    }
    var targetP;
    if (position !== "inner") {
        this._getRangeSections(function (p) {
            targetP = p;
        });
        if (targetP.children("ol").length > 0 || targetP.children("ul").length > 0) {
            targetP = this.createPElement().insertAfter(targetP);
        }
    }
    var $newImg;
    if (position === "center") {
        var txt = targetP.text();
        var insertTag;
        if (txt === "" || txt === "\u200B") {
            insertTag = targetP;
        } else {
            var $p = this.createPElement();
            insertTag = $p.insertAfter(targetP);
        }
        insertTag.css("text-align", "center");
        $newImg = this._createImage(url, width, height).css(margin).appendTo(insertTag);
    } else if (position === "inner") {//行内图片
        this.lineInnerImage(url, width, height);
        return;
    } else {
        insertTag = targetP;
        targetP.addClass("clearfix");
        $newImg = this._createImage(url, width, height).css(margin).css("float", position).appendTo(insertTag);
    }
    var $span = this._getSpan().insertBefore($newImg);
    this._getSpan().insertAfter($newImg);
    if (position !== "inner") {
        $newImg.css("text-align", position);
    }
    var nextPelement = insertTag.next();
    if (nextPelement.length === 0) {
        nextPelement = this.insertPElement();
    }
    if(params.isAuto){
        $newImg.width("100%");
        $newImg.height("auto");
    }
    if(params.link){
        if(params.link === ""){
            $newImg.removeAttr("link");
        }else{
            $newImg.attr("link",params.link);
        }        
    }
    setTimeout(function () {
        if (position === "center") {
            _this.moveToEnd(nextPelement);
        } else {
            _this.moveToEnd($span);
        }
    }, 100);
    return $newImg;
};
/**插入行内图片***/
Kedit.prototype.lineInnerImage = function (url, width, height, isTd) {
    var $newImg = this._createImage(url, width, height).addClass("k_inner_image").css({ "margin-left": "1px", "margin-right": "1px" });
    var insertSpan, pEl, gifSPAN, nextspan, _this = this;
    insertSpan = this._getInsertSpan();
    pEl = insertSpan.parent();
    while (pEl.length > 0) {
        if (pEl.hasClass("_section_div_")) {
            break;
        }
        pEl = pEl.parent();
    }
    gifSPAN = this._getSpan();
    gifSPAN.append($newImg);
    var emptTxt = this._createEmptyTextNode();
    gifSPAN.append($newImg);
    gifSPAN.append(emptTxt);
    gifSPAN.insertAfter(insertSpan);
    nextspan = this._getSpan().insertAfter(gifSPAN);
    $newImg.css("border", "1px solid #F0F0F0");
    if (!isTd) {
        if (pEl.next().length === 0) {
            this.createPElement().insertAfter(pEl);
        }
    }
    setTimeout(function () {
        //图片居中修饰
        var top = (gifSPAN.height() - $newImg.height()) / 2;
        $newImg.css({
            'position': 'relative',
            'top': top + "px"
        });
        _this.moveToEnd(nextspan);
    }, 100);
};
/**
 * 更新图片大小、边距
 * **/
Kedit.prototype.updateImage = function (params) {
    var $img = params["$img"];
    var css = {
        "margin-top": params["top"] + "px",
        "margin-left": params["left"] + "px",
        "margin-bottom": params["bottom"] + "px",
        "margin-right": params["right"] + "px",
        "width": params["width"],
        "height": params["height"]
    };
    $img.css(css);
    if(params.isAuto){
        $img.width("100%");
        $img.height("auto");
    }
    if(params.link){
        if(params.link === ""){
            $img.removeAttr("link");
        }else{
            $img.attr("link",params.link);
        }        
    }
    var $p = $img.parent();
    var align = params["position"];
    var style = $img.attr("style");
    var go = false;
    if (align === "center") {
        go = true;
        style = style.replace(/float:\s*(left|right)/g, "");
        var txt = $p.text().replace(/\u200B/g, "");
        if (txt === "") {
            $p.css("text-align", "center").removeClass("clearfix");
        } else {
            var newP = this.createPElement().insertAfter($p).css("text-align", "center");
            $img.detach().appendTo(newP);
            this._getSpan().insertAfter(newP);
            $p.removeClass("clearfix");
            if (newP.next("._section_div_").length === 0) {
                this.createPElement().insertAfter(newP);
            }
            this.moveToEnd(newP);
        }
    } else if (align !== "inner") {
        $p.css("text-align", "left").addClass("clearfix");
        var v;
        if (align === "left") {
            v = "float:left";
            style = style.replace(/(text-align|float):\s*(center|right)/g, v);
        } else {
            v = "float:right";
            style = style.replace(/(text-align|float):\s*(center|left)/g, v);
        }
        go = true;
    }
    $img.attr("style", style);
    if (go) {
        $img.css("text-align", align);
    }
};
Kedit.prototype._createImage = function (url, width, height) {
    var $img = $("<img id='" + getUUID() + "' tabindex='0' src='" + url + "' style='width:" + width + "px;height:" + height + "px' />");
    var _this = this;
    setTimeout(function () {
        _this._bindImageEvents($img);
    }, 10);
    return $img;
};
Kedit.prototype._bindImageEvents = function ($img) {
    var _this = this;
    //$img[0].ondragstart = function(){return false};
    $img.keyup(function (e) {
        if (e.which === 46) {
            //console.log("delete img....");
        }
    }).keydown(function () {
        //console.log("key down >>>>>>>>>>>>>>");
    }).mousedown(function (e) {
        //console.log("image events >>>>> ");
        var box = $(this);
        var me = box.data("edit");
        var isEmotion = box.hasClass("_emotion_");
        me._closeCxtMenuImd();
        if (e.which === 3) {
            stopDefaultctxMenu();
            if (!isEmotion) {
                if (_this["resizeBox"]) {
                    if (_this["resizeBox"].target && _this["resizeBox"].target[0] === box[0]) {
                        _this["resizeBox"].unbind();
                    }
                }
            }
        } else {
            if (me["tipWindow"]) {
                me["tipWindow"].hide();
            }
            if (!_this["resizeBox"] && !isEmotion) {
                _this._createResizeBox(box);
            }
            if (_this["resizeBox"] && !isEmotion) {
                _this["resizeBox"].bind(box);
            }
        }
        e.preventDefault();
        return false;
    }).mouseup(function (e) {
        _this.clickActivedDomObject = $(this);
        _this.clickActivedDomObject.addClass("k_edit_actived_object");
        var self = $(this);
        var isEmotion = self.hasClass("_emotion_");
        var isInnerImg = self.hasClass("k_inner_image");
        var me = self.data("edit");
        if (e.which === 3) {
            me.openTIPWindow({
                top: e.pageY,
                left: e.pageX,
                img: self
            }, function (body, prs) {
                if (!me["imgTip"]) { //
                    me["imgTip"] = $("<div><p class='_delete_imag' style='cursor:pointer;'><i class='fa fa-cancel' style='padding-right:4px;'></i>" + eConfig.label.deleteImg + "</p>" +
                        "<p class='_setborder_imag' style='cursor:pointer;'><i class='fa fa-check-empty' style='padding-right:4px;'></i>" + eConfig.label.setborder + "</p>" +
                        "<p class='_seting_imag' style='cursor:pointer;'><i class='fa fa-edit' style='padding-right:4px;'></i>" + eConfig.label.modify + "</p>" +
                        "<p class='_section_imag' style='cursor:pointer;'><i style='padding-right:4px;' class='fa fa-exchange'></i>" + eConfig.label.setSectionWidth + "</p>" +
                        "<p class='_resection_imag' style='cursor:pointer;display:none;'><i style='padding-right:4px;' class='fa fa-resize-horizontal'></i>" + eConfig.label.resetSectionWidth + "</p>" +
                        "<p class='_move_imag' style='cursor:pointer;'><i class='fa fa-move' style='padding-right:4px;'></i>" + eConfig.label.move +
                        "<p class='_flow_imag' style='cursor:pointer;display:none;'><i class='fa fa-share-2' style='padding-right:4px'></i>" + eConfig.label.editFlow + "</div>"
                    );
                    me["imgTip"].children("p._delete_imag").click(function () {
                        if (me.movingAcn) {
                            me.movingAcn.hide();
                        }
                        var tip = $(this).parent();
                        tip.parent().parent().hide();
                        var $img = tip.data("image");
                        //delete me.FLOW_CACHE[$img.attr("id")];
                        var $p = $img.parent();
                        while ($p.length > 0) {
                            if ($p.hasClass("_section_div_")) {
                                break;
                            }
                            $p = $p.parent();
                        }
                        //删除操作 做记录                        
                        me._putUndoDataByNodeEl($p);
                        var imgWrap = $img.parent();
                        if (imgWrap.hasClass("._k_edit_img_wrap")) {
                            imgWrap.remove();
                        }
                        tip.removeData("image");
                        if ($p.contents().length === 0) {
                            $p.append('<span style="' + eConfig.defaultStyle + '" id="' + getUUID() + '">\u200B</span>');
                        }
                        $p.css("text-align", "left");
                        me.moveToEnd($p);
                        if ($p.children("img").length === 0) {
                            $p.removeClass("clearfix");
                        }
                        $img.remove();
                        if (me.opts.onDeleted) {
                            me.opts.onDeleted.call($img, $img.attr("src"));
                        }
                    });
                    me["imgTip"].children("p._seting_imag").click(function () {
                        var tip = $(this).parent();
                        tip.parent().parent().hide();
                        var img = tip.data("image");
                        var style = me._getCopyStyle(img);
                        var _prs = $.extend({
                            "undo": false,
                            "needRange": false,
                            "width": img.outerWidth() + "",
                            "height": img.outerHeight() + "",
                            "$img": img
                        }, style);
                        me.openInsertImageWindow("updateImage", _prs);
                    });
                    //_resection_imag
                    me["imgTip"].children("p._section_imag").click(function () {
                        var tip = $(this).parent();
                        tip.parent().parent().hide();
                        var $img = tip.data("image");
                        var $p = $img.parent();
                        while ($p.length > 0) {
                            if ($p.hasClass("_section_div_")) {
                                break;
                            }
                            $p = $p.parent();
                        }
                        _this.startPElement = $p;
                        _this.endPElement = $p;
                        _this.setSectionWidth();
                    });
                    //_resection_imag
                    me["imgTip"].children("p._resection_imag").click(function () {
                        var tip = $(this).parent();
                        tip.parent().parent().hide();
                        var $img = tip.data("image");
                        var $p = $img.parent();
                        while ($p.length > 0) {
                            if ($p.hasClass("_section_div_")) {
                                break;
                            }
                            $p = $p.parent();
                        }
                        _this.startPElement = $p;
                        _this.endPElement = $p;
                        _this.resetSectionWidth();
                    });
                    me["imgTip"].children("p._move_imag").click(function () {
                        var tip = $(this).parent();
                        var $img = tip.data("image");
                        me._setMovingTargets($img, true);
                        tip.parent().parent().hide();
                    });
                    //边框设置
                    me["imgTip"].children("p._setborder_imag").click(function () {
                        var tip = $(this).parent();
                        tip.parent().parent().hide();
                        me.openBorderForm(me["imgTip"].data("image"));
                    });
                    //流程编辑
                    me["imgTip"].children("p._flow_imag").click(function () {
                        var flowImg = me["imgTip"].data("image");
                        var imgId = flowImg.attr("id");
                        var flowData = me.FLOW_CACHE[imgId];
                        me.flowOpen(flowData, flowImg);
                    });
                }
                var $ss = me["imgTip"].children("p._seting_imag");
                var $s1 = me["imgTip"].children("p._section_imag");
                var $s2 = me["imgTip"].children("p._move_imag");
                var $s3 = me["imgTip"].children("p._setborder_imag");
                var $s4 = me["imgTip"].children("p._resection_imag");
                var $s5 = me["imgTip"].children("p._flow_imag");
                if (isEmotion || isInnerImg) {
                    $ss.hide();
                    $s1.hide();
                    $s2.hide();
                    if (isEmotion) {
                        $s3.hide();
                    } else {
                        $s3.show();
                    }
                    $s4.hide();
                } else {
                    $ss.show();
                    $s1.show();
                    $s2.show();
                    $s3.show();
                }
                var $img = prs["img"];
                if ($img.hasClass("k_editor_flow_img")) {
                    var id = $img.attr("id");
                    //查询sessionStorage
                    if (me.FLOW_CACHE[id]) {
                        $s5.show();
                    } else {
                        $s5.hide();
                    }
                } else {
                    $s5.hide();
                }
                me["imgTip"].data("image", $img);
                if (!isEmotion && !isInnerImg) {
                    var tmpSe = me["imgTip"].children("p._resection_imag");
                    var pElSe = $img.parent();
                    while (pElSe.length > 0) {
                        if (pElSe[0].tagName === "DIV") {
                            break;
                        }
                        pElSe = pElSe.parent();
                    }
                    if (pElSe.css("margin-left") !== "0px") {
                        tmpSe.show();
                    } else {
                        tmpSe.hide();
                    }
                }
                body.append(me["imgTip"]);
            });
        } else {
            if (!isEmotion && !isInnerImg) {
                me._setMovingTargets(self, true);
            }
        }
        return false;
    }).data("edit", this);
};
/**
* 上传文件
* ***/
Kedit.prototype.upload = function (params) {
    var range = this.range;
    if (range) {
        var linkName = params["linkName"];
        var addr = params["url"];
        var a = $('<a flag="1" target="_blank" href="' + addr + '" id="' + getUUID() + '">' + linkName + '</a>');
        var endContainer = range.endContainer;
        var endOffset = range.endOffset;
        var nodeValue = endContainer.nodeValue;
        var wrap = $(endContainer.parentNode);
        var copyStyle = this._getCopyStyle(wrap);
        var aEleStyle = $.extend({}, copyStyle);
        aEleStyle["text-decoration"] = "underline";
        a.css(aEleStyle);
        if (nodeValue !== "" && nodeValue !== "\u200B") {
            var tags = $(this._text2spanWrap(nodeValue, 0, endOffset, false));
            tags.css(copyStyle);
            if (wrap[0].tagName === "TD") {
                wrap.html("");
                tags.appendTo(wrap);
            } else {
                tags.insertAfter(wrap);
                wrap.remove();
            }
            var target;
            tags.each(function () {
                var $t = $(this);
                if ($t.hasClass("_wrap_target_node_")) {
                    target = $t.removeClass("_wrap_target_node_");
                }
            });
            a.insertAfter(target);
            this.moveToEnd(this._getSpan().insertAfter(a).css(copyStyle));
        } else {
            wrap.html("");
            if (wrap[0].tagName === "TD") {
                wrap.append(a);
                var newSpan = this._getSpan().css(copyStyle).appendTo(wrap);
                this.moveToEnd(newSpan);
            } else {
                a.appendTo(wrap);
                if (wrap.prev().length === 0) {
                    this._getSpan().css(copyStyle).insertBefore(wrap);
                }
                this.moveToEnd(this._getSpan().css(copyStyle).insertAfter(wrap));
            }
        }
        this._bindAEleEvents(a);
        return a;
    }
};
/**
* 分割线
* **/
Kedit.prototype.split = function (params) {
    var section = this.getRangeSection();
    if (section) {
        var target;
        if (this.isEmptySectionFn(section)) {
            target = section;
        } else {
            target = this.createPElement();
            target.insertAfter(section);
        }
        target.css(eConfig.lineCss).addClass("_exclude_ k_split_line").attr({
            "line": "true",
            "contenteditable": "false"
        });
        var next = target.next();
        if (next.length === 0) {
            next = this.createPElement();
            next.insertAfter(target);
        }
        // console.log("split move ----");
        this.moveToEnd(next);
        this._bindSplitLineEvent(target);
    }
};
Kedit.prototype._bindSplitLineEvent = function ($line) {
    var _this = this;
    $line.on({
        "mousedown": function (e) {
            if (e.which === 3) {
                stopDefaultctxMenu();
            }
            return false;
        },
        "mouseup": function (e) {
            var $t = $(this);
            var _this = $t.data("_this");
            _this.showSplitTip(e, $t);
            return false;
        }
    }).data("_this", _this);
};
Kedit.prototype.showSplitTip = function (e, self) {
    var _this = this;
    _this.openTIPWindow({
        top: e.pageY,
        left: e.pageX,
        self: self
    }, function (body, prs) {
        if (!_this["splitmenu"]) {
            _this["splitmenu"] = $("<div><p class='_delete_split' style='cursor:pointer;'>" + eConfig.label.deleteSplit + "</p><p class='_seting_split' style='cursor:pointer;'>" + eConfig.label.modify + "</p></div>");
            _this["splitmenu"].children("._delete_split").click(function () {
                var $t = $(this).parent();
                var $tag = $t.data("split");
                //删除操作 做记录                        
                _this._putUndoDataByNodeEl($tag);
                var activedSection = $tag.next();
                if (activedSection.length === 0) {
                    activedSection = $tag.prev();
                }
                _this.closeTIPWindow();
                $tag.remove();
                _this.moveToEnd(activedSection);
            });
            _this["splitmenu"].children("._seting_split").click(function () {
                var $t = $(this).parent();
                var $tag = $t.data("split");
                _this.closeTIPWindow();
                _this.openSplitWindow({
                    "tag": $tag
                });
            });
        }
        _this["splitmenu"].data("split", prs["self"]);
        body.append(_this["splitmenu"]);
    });
};
Kedit.prototype.openSplitWindow = function (params) {
    var _this = this;
    this.openWindow({
        title: eConfig.label.splitLineUpdate,
        width: 300,
        height: 200,
        notIfr: true,
        contentFn: function (body, prs) {
            if (!_this["splitForm"]) {
                _this["splitForm"] = $(eConfig.splitForm);
                _this["splitForm"].find("#_line_size").on("change", function () {
                    var size = $(this).val();
                    var params = _this["splitForm"].data("params");
                    var tag = params["tag"];
                    tag.css("border-bottom-width", size);
                });
                _this["splitForm"].find("#_line_style").on("change", function () {
                    var style = $(this).val();
                    var params = _this["splitForm"].data("params");
                    var tag = params["tag"];
                    tag.css("border-bottom-style", style);
                });
                _this["splitForm"].find("#_line_top").on("input", function () {
                    var v = $(this).val();
                    if (v !== "") {
                        var params = _this["splitForm"].data("params");
                        var tag = params["tag"];
                        tag.css("margin-top", parseInt(v) + 4 + "px");
                    }
                });
                _this["splitForm"].find("#_line_bottom").on("input", function () {
                    var v = $(this).val();
                    if (v !== "") {
                        var params = _this["splitForm"].data("params");
                        var tag = params["tag"];
                        tag.css("margin-bottom", parseInt(v) + 4 + "px");
                    }
                });
                _this._createWindowColorPicker();
            }
            var _color = params["tag"].css("border-bottom-color").toHexColor();
            var _size = params["tag"].css("border-bottom-width");
            var _style = params["tag"].css("border-bottom-style");
            var mTop = parseInt(params["tag"].css("margin-top").replace("px", "") - 4);
            var mBottom = parseInt(params["tag"].css("margin-bottom").replace("px", "") - 4);
            _this["splitForm"].find("#_line_top").val(mTop);
            _this["splitForm"].find("#_line_bottom").val(mBottom);
            var loopFn = function () {
                var $t = $(this);
                if ($t.val() === _size) {
                    $t.prop("selected", true);
                } else {
                    $t.prop("selected", false);
                }
            };
            _this["splitForm"].find("#_line_size").children().each(loopFn);
            _this["splitForm"].find("#_line_style").children().each(loopFn);
            var $color = _this["splitForm"].find("#_line_color_").val(_color).css("background-color", _color);
            _this["splitForm"].data("params", prs);
            body.append(_this["splitForm"]);
            var ifrPos = _this[_this.windowName + "_iframe"].offset();
            var picker = _this[_this.windowName].data("colorPicker");
            picker.unbindTarget();
            picker.opts.positionFix = {
                left: ifrPos.left + 4,
                top: ifrPos.top + 4
            };
            picker.setTarget($color).setValue(_color);
            picker.opts.change = function (hex, opacity) {//注册颜色变化函数
                params["tag"].css("border-bottom-color", hex);
            };
        }
    }, params, this.setWindowColorPickerPosition);
    this.setWindowColorPickerPosition();
};
/***
 * 插入地图，走插入图片逻辑
 * ***/
Kedit.prototype.insertMap = function (imgData, width, height) {
    var src = imgData;
    if (typeof this.opts.onInsertMap === "function") {
        src = this.opts.onInsertMap(imgData);
    }
    var prs = {
        "undo": false,
        "needRange": false,
        "url": src,
        "width": width,
        "height": height,
        "position": "left"
    };
    var img = this.picture(prs);
    img.addClass("k_editor_map_img");
};
/**预览**/
Kedit.prototype.preview = function (params) {
    var page = eConfig.preview;
    window["curEditor"] = this;
    window["_isMobile_e"] = this.opts.mobile;
    if (window["_isMobile_e"]) {
        window["_mobile_w"] = this.$fixInput.outerWidth();
        window["_mobile_h"] = this.$fixInput.outerHeight();
    }
    $B.window({
        title: eConfig.tools.preview,
        full: true,
        dataType: 'iframe',
        url: page
    });
};
Kedit.prototype.fullprint = function (prs, button) {
    //console.log("full print >>>>>>");
    var srcWrap;
    var rangeInfo = this._getRangeInfo();
    if (this.jqObj.data("isFull")) {
        this.jqObj.removeData("isFull");
        srcWrap = this.jqObj.data("srcWrap");
        this.jqObj = this.jqObj.detach();
        srcWrap.append(this.jqObj);
        this.jqObj.removeData("srcWrap");
        if (this.fullWrap) {
            this.fullWrap.remove();
            this.fullWrap = undefined;
        }
        button.children("i").removeClass("fa-resize-small").addClass("fa-resize-full");
        this.jqObj.height(this.jqObj.data("src_height"));
        this.jqObj.width(this.jqObj.data("src_width"));
        if (this.opts.mobile) {
            this.$inputWrap.css("border-left-width", this.jqObj.data("src_border_l"));
            this.$inputWrap.css("border-right-width", this.jqObj.data("src_border_r"));
        }
    } else {
        var lwidth;
        if (this.opts.mobile) { //处理浮动文本的 位置问题
            lwidth = this.$inputWrap.css("border-left-width");
            var rwidth = this.$inputWrap.css("border-right-width");
            this.jqObj.data("src_border_l", lwidth);
            this.jqObj.data("src_border_r", rwidth);
            console.log(" lwidth =" + lwidth);
        }

        this.fullWrap = $("<div class='k_box_size' style='position: absolute; z-index:666666; top: 0px; left: 0px; width: 100%; height: 100%;'></div>");
        var $b = _getBody();
        this.fullWrap.appendTo($b);
        srcWrap = this.jqObj.parent();
        this.jqObj.data("isFull", true);
        this.jqObj.data("srcWrap", srcWrap);
        if (!this.jqObj.data("src_height")) {
            this.jqObj.data("src_height", this.jqObj.height());
        }
        if (!this.jqObj.data("src_width")) {
            this.jqObj.data("src_width", this.jqObj.width());
        }
        this.jqObj = this.jqObj.detach();
        this.fullWrap.append(this.jqObj);
        this.jqObj.outerHeight($b.height());
        this.jqObj.outerWidth($b.width());
        button.children("i").removeClass("fa-resize-full").addClass("fa-resize-small");
        if (this.opts.mobile) {
            var newBorderWidth = this.$fixInput.offset().left;
            this.$inputWrap.css("border-left-width", newBorderWidth + "px");
            var scrlWidth = $B.getScrollWidth() + 17;
            this.$inputWrap.css("border-right-width", ($b.width() - newBorderWidth - this.$fixInput.width() - scrlWidth) + "px");
        }
    }
    var _h = this.$inputWrap.siblings(".k_edit_tools_wrap").outerHeight() + 4;
    this.$inputWrap.css("border-top-width", _h);
    this.rebuildUserRange(rangeInfo);
};
Kedit.prototype.showVersion = function () {
    $B.message({ title: eConfig.label.version, height: 150, message: "<span style='line-height:1.5em'>version：" + VERVar + "</span><br/><span style='line-height:1.5em'>site：" + VERSite + "</span><br/><span style='line-height:1.5em'>release：" + VERDate + "</span>" });
};
/**
 * 使用帮助
 * ****/
Kedit.prototype.help = function () {
    var body = _getBody();
    var w = body.width() - 300;
    var h = body.height() - 100;
    $B.window({
        dataType: 'html',
        title: eConfig.label.help,
        width: w,
        height: h,
        url: 'help.html',
        onClosed: function () {
            clearInterval(window["_helperScrollChecking"]);
        }
    });
};
/***
 * 移动设备模拟
 * ***/
Kedit.prototype.mobile = function (params) {
    var _this = this;
    var size = params.phonesize.split("*");
    var width = parseInt(size[0]);
    var height = parseInt(size[1]);
    var floats;
    if (this.$inputWrap) {
        floats = this.$inputWrap.children(".k_edit_float_panel").hide();
    }
    this.$fixInput.parent().css({
        "border-left": "none",
        "border-right": "none"
    });
    this.$fixInput.css({
        "border-top": "20px solid #171717",
        "margin": "0 auto",
        "width": width,
        "min-height": height + "px"
    });
    var wrap = _this.$fixInput.parent();
    var marginRight = parseInt(_this.$fixInput.css("margin-left").replace("px", ""));
    var borderl = marginRight + "px solid rgb(242,242,242)";
    var scrlWidth = $B.getScrollWidth();
    var borderR = (marginRight - scrlWidth) + "px solid rgb(242,242,242)";
    wrap.css({
        "border-left": borderl,
        "border-right": borderR,
        "background": "rgb(242,242,242)"
    });
    if (floats) {
        floats.show();
    }
};